ОК, так как мне не удалось использовать функцию mnist с более новой версией Anaconda (устаревшая ошибка с предупреждением об ошибке), я преобразовал файлы в csv, используя этот код для загрузки и обучения:
import csv with `open('C:\\Users\\User\\datasets\\mldata\\fetch\\mnist_train.csv') as sample, open('randomized.csv', "w", newline='') as out:`
csv1=csv.reader(sample)
#header = next(csv1, None)
csv_writer = csv.writer(out)
#if header:
# csv_writer.writerow(header)
csv_writer.writerows(sorted(csv1, key=lambda x:int(x[0])))
import csv
fname_in = 'randomized.csv'
fname_out = 'new_randomized.csv'
with open(fname_in, 'r') as fin, open(fname_out, 'w', newline='') as fout:
reader = csv.reader(fin)
writer = csv.writer(fout)
for row in reader:
writer.writerow(row[1:])
with open ("randomized.csv", "r") as csvfile:
reader = csv.reader(csvfile)
collected = []
for row in reader:
collected.append(row[0])
with open("extracted_randomized_column.csv", "w", newline='') as csv_file:
writer = csv.writer(csv_file, delimiter=',')
for line in collected:
writer.writerow(line)
with open('new_randomized.csv') as sample:
csv1=csv.reader(sample)
c = list(csv1)
collected = []
for i in range(len(c)):
s = ''
for j in range(len(c[i])):
if int(c[i][j]) > 128:
s = s + '1'
else:
s = s + '0'
collected.append(s)
with open("bw_output.csv", "w", newline='') as csv_file:
writer = csv.writer(csv_file, delimiter=',')
for line in collected:
writer.writerow(line)
from PIL import Image
A = np.array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
B = np.reshape(A, (-1, 28))
img = Image.fromarray(B)
img.show()
But I think I am missing some steps because I have errors with the train test split function.
Я хотел бы знать, как использовать разделенную модель поезда и теста:
from sklearn.model_selection import train_test_split
train_img, test_img, train_lbl, test_lbl = train_test_split(
data, data.target, test_size=1/7.0, random_state=0)
, поскольку я получил следующее сообщение об ошибке:
AttributeError Traceback (most recent call last)
<ipython-input-43-4744a5acdbfa> in <module>
1 from sklearn.model_selection import train_test_split
2 train_img, test_img, train_lbl, test_lbl = train_test_split(
----> 3 data, data.target, test_size=1/7.0, random_state=0)
~\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
4374 if self._info_axis._can_hold_identifiers_and_holds_name(name):
4375 return self[name]
-> 4376 return object.__getattribute__(self, name)
4377
4378 def __setattr__(self, name, value):
AttributeError: 'DataFrame' object has no attribute 'target'
Любой совет?