在scikit-learn

时间:2018-02-18 04:25:42

标签: python-3.x scikit-learn neural-network perceptron

我在sci-kit学习中实施perceptron在线培训时遇到错误。我已经引用了这个堆栈溢出question作为参考,但我无法弄清楚我的错误。

我正在试验的数据集有1000行和11列。 10是功能列,1是类标签列。我附上代码供您参考:

import numpy as np
import pandas as pd
from pandas import Series,DataFrame
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import Perceptron

df = pd.read_csv(r'C:\Users\sjrk\Desktop\ML\Machine learning practise\d-10.csv')

X = df[['D-0','D-1','D-2','D-3','D-4','D-5','D-6','D-7','D-8','D-9']]
y = df['C']

train_test_split =X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.30, random_state=0)

scalar_model = StandardScaler()
scalar_model.fit(X_train)
X_train_std = scalar_model.transform(X_train)
X_test_std = scalar_model.transform(X_test)
#perceptron initialization
ppn = Perceptron(n_iter = 100,eta0=0.1,random_state=0)
# Online training
num_samples = X_train_std.shape[0]
classes_y =  np.unique(y_train)
X_train_std = X_train_std.reshape(700,10)
y_train = y_train.reshape(700,1)

for i in range(num_samples):

    ppn.partial_fit(X_train_std[i], y_train[i], classes = classes_y )

这样会抛出一个错误:

ValueError: Expected 2D array, got 1D array instead:
array=[ 1.6540008  -0.09311816 -0.17325239 -1.21276374 -1.27102032 -0.51813835
  1.74932495 -1.49606596  0.61310441 -0.66910947].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

我在网上培训中重塑了一些问题。 请帮帮我。

由于

0 个答案:

没有答案