Estoy tratando de probar y entrenar mis datos usando MLPRegressor, pero siempre termino con el mismo error para la línea "classifier.fit(xtrain, ttrain)", soy relativamente nuevo en python, así que esto me ha tenido atascado por un tiempo ahora
iv traté de usar ravel() y remodelarlo, pero tampoco funcionó. ¿Alguien tiene algún buen consejo?
data = pd.read_excel("data.xlsx")
print(data)
from sklearn import preprocessing
from sklearn.preprocessing import MinMaxScaler
inputs = data.values[:,:8].astype(float)
#Normalize the inputs
scaler = MinMaxScaler()
scaled = scaler.fit_transform(inputs)
print(inputs.ptp(axis=0))
print(scaled.ptp(axis=0))
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df = pd.read_excel("ENB2012_data.xlsx")
x = df.iloc[:,1:2].values
y = df.iloc[:,2].values
df
from sklearn.neural_network import MLPRegressor
regressor = MLPRegressor(max_iter=5000)
regressor.fit(inputs, scaled)
outputs = regressor.predict(inputs)
print("MLP Regressor: \n", outputs)
from sklearn.metrics import mean_absolute_error
regressor = MLPRegressor(max_iter=5000)
regressor.fit(inputs, scaled)
outputs = regressor.predict(inputs)
print(mean_absolute_error(outputs, scaled))
from numpy.lib.shape_base import split
from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.base import ClassifierMixin
#split the data to training and testing
xtrain, xtest, ttrain, ttest = train_test_split(outputs, scaled)
#train the classifiers
classifier = SVC(gamma = "auto")
classifier.fit(xtrain, ttrain)
ytrain = classifier(xtrain)
ytest = classifier.predict(xtest)
Editar:
ValueError Traceback (most recent call
last)
<ipython-input-229-62670b265a4b> in <module>()
4 #train the classifiers
5 classifier = SVC(gamma = "auto")
----> 6 classifier.fit(xtrain, ttrain)
7 ytrain = classifier(xtrain)
8 ytest = classifier.predict(xtest)
4 frames
/usr/local/lib/python3.7/dist-packages/sklearn/utils/validation.py in
column_or_1d(y, warn)
1037
1038 raise ValueError(
1039 "y should be a 1d array, got an array of shape {}
instead.".format(shape)
1040 )
1041
ValueError: y should be a 1d array, got an array of shape (576, 8)
instead.
Solución del problema
Si bien necesitamos más contexto para responder a su pregunta, debe comenzar usando np.shape(input)
para verificar la forma de su input
variable.
Deberías comprobar después de esta línea:
inputs = data.values[:,:8].astype(float)
# Check with np.shape
print(np.shape(input))
# Expected output:
...we need to know this
Quieres una matriz unidimensional para esto. Aquí están algunos ejemplos,
# This is a 3x1 shape (1-dimensional).
np.shape([0, 1, 2])
# This is a 3x3 shape (multi-dimensional).
np.shape([[0, 1, 2],[3, 4, 5],[6, 7, 8]])
No hay comentarios:
Publicar un comentario