'Perceptron and classification task

There is data and a classification task:

    from sklearn.model_selection import GridSearchCV
    from sklearn.preprocessing import label_binarize
    from sklearn.linear_model import Perceptron
    from sklearn.calibration import CalibratedClassifierCV
    from sklearn.model_selection import train_test_split
    from sklearn.neighbors import RadiusNeighborsClassifier
    from sklearn.metrics import roc_curve, precision_recall_curve,accuracy_score
    df = pd.read_csv(R'C:\Users\...\glass.csv', sep=',',decimal = '.')
    
    x = scaled_df.drop('Type', axis = 1)
    y = scaled_df['Type']
    y_bin = label_binarize(y,classes =[1, 2, 3, 4, 5, 6, 7] )
    n_classes = y_bin.shape[1]
    x_train, x_test, y_train, y_test = train_test_split(x, y_bin, test_size=0.3, random_state=0)

    ppn = Perceptron()
    ppn_grid = GridSearchCV(estimator=ppn, param_grid={
    'alpha': np.linspace(0, 1, 50),
    'max_iter': [x for x in range(1, 200)]
    }, n_jobs=-1)
    ppn_grid.fit(x_train, y_train)  

Up to this point, everything is going fine. But during the execution of the line

python ppn_grid.fit(x_train, y_train)

I get this error ValueError: y should be a 1d array, got an array of shape (149, 7) instead.

Also, this code with the same data works fine

rnc = RadiusNeighborsClassifier(radius = 1)
rnc_grid = GridSearchCV(rnc, {'radius': np.arange(0,10)})
rnc_grid.fit(x_train, y_train)
rnc = RadiusNeighborsClassifier(radius=best_radius)
rnc.fit(x_train, y_train)

UPD: Input data looks like this

RI,Na,Mg,Al,Si,K,Ca,Ba,Fe,Type

1.52101,13.64,4.49,1.1,71.78,0.06,8.75,0,0,1 1.51761,13.89,3.6,1.36,72.73,0.48,7.83,0,0,1 1.51618,13.53,3.55,1.54,72.99,0.39,7.78,0,0,1 1.51766,13.21,3.69,1.29,72.61,0.57,8.22,0,0,1

Then i'm scaling the data

num_columns = [df.columns[0:9]]
categorial_columns = [df.columns[9]]
scaler = preprocessing.MinMaxScaler()
col = total_num.columns
total_num[col] = scaler.fit_transform(total_num[col])
scaled_df = pd.DataFrame(total_num, columns = col)
scaled_df['Type'] = type_col


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source