代码:
import numpy
from matplotlib.mlab import PCA
file_name = "store1_pca_matrix.txt"
ori_data = numpy.loadtxt(file_name,dtype='float', comments='#', delimiter=None, converters=None, skiprows=0, usecols=None, unpack=False, ndmin=0)
result = PCA(ori_data)
Run Code Online (Sandbox Code Playgroud)
这是我的代码.虽然我的输入矩阵没有nan和inf,但我确实得到了下面所述的错误.
raise LinAlgError("SVD did not converge") LinAlgError: SVD did not converge
Run Code Online (Sandbox Code Playgroud)
有什么问题?
这是我为Kosaraju算法做的代码的第一部分.
###### reading the data #####
with open('data.txt') as req_file:
ori_data = []
for line in req_file:
line = line.split()
if line:
line = [int(i) for i in line]
ori_data.append(line)
###### forming the Grev ####
revscc_dic = {}
for temp in ori_data:
if temp[1] not in revscc_dic:
revscc_dic[temp[1]] = [temp[0]]
else:
revscc_dic[temp[1]].append(temp[0])
print revscc_dic
######## finding the G#####
scc_dic = {}
for temp in ori_data:
if temp[0] not in scc_dic:
scc_dic[temp[0]] = [temp[1]]
else:
scc_dic[temp[0]].append(temp[1])
print scc_dic
##### iterative dfs …
Run Code Online (Sandbox Code Playgroud) 这是我的karger min cut算法的代码.据我所知,我实现的算法是正确的.但我没有得到正确答案.如果有人可以检查出了什么问题,我将不胜感激.
import random
from random import randint
#loading data from the text file#
with open('data.txt') as req_file:
mincut_data = []
for line in req_file:
line = line.split()
if line:
line = [int(i) for i in line]
mincut_data.append(line)
#extracting edges from the data #
edgelist = []
nodelist = []
for every_list in mincut_data:
nodelist.append(every_list[0])
temp_list = []
for temp in range(1,len(every_list)):
temp_list = [every_list[0], every_list[temp]]
flag = 0
for ad in edgelist:
if set(ad) == set(temp_list):
flag = …
Run Code Online (Sandbox Code Playgroud) 这是合并排序的代码..代码工作得很好,并对数字进行排序.但是,如果我们要更大的数据必须进行排序,那么就会出现问题.要排序的数据包含不重复的数字.但是在排序之后,有一些数字会重复多次.我不明白为什么会这样......当我给出100000个数字的数据集时会发生这种情况.当要对较小的数据进行排序时,代码非常有效.
def mergeSort(alist):
if len(alist)>1:
mid = len(alist)/2
lefthalf = alist[:mid]
righthalf = alist[mid:]
mergeSort(lefthalf)
mergeSort(righthalf)
i=0
j=0
k=0
while i<len(lefthalf) and j<len(righthalf):
if lefthalf[i]<righthalf[j]:
alist[k]=lefthalf[i]
i=i+1
else:
alist[k]=righthalf[j]
j=j+1
k=k+1
while i<len(lefthalf):
alist[k]=lefthalf[i]
i=i+1
k=k+1
while j<len(righthalf):
alist[k]=righthalf[j]
j=j+1
k=k+1
print("select the file: ")
file_name = tkFileDialog.askopenfile(mode='r', title='Select word list file')
inv_data = np.loadtxt(file_name,dtype='float', comments='#', delimiter=None, converters=None, skiprows=0, usecols=None,
unpack=False, ndmin=0)
mergeSort(inv_data)
print("sorted list :", inv_data)
Run Code Online (Sandbox Code Playgroud)
数据集位于以下链接 http://spark-public.s3.amazonaws.com/algo1/programming_prob/IntegerArray.txt
我想使用 ARIMAResults 类进行 ARIMA 建模。任何人都可以引用普通 ARIMA 类和 ARIMAResults 类之间的区别吗?另外,有人可以通过举个例子来帮助我做 ARIMAResults 吗?我有一组数据,必须拟合 ARIMA 模型并预测值。