عند محاولة تدريب model ( نموذج ) يظهر لي الخطأ التالي Expected 2D array, got 1D array instead الكود:
from sklearn.preprocessing importLabelEncoderimport pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model importLinearRegression# إنشاءداتا
data ={'size':[100,30,50,200,2],'class':['big','small','medium','verybig','verysmall']}
df = pd.DataFrame(data)
le =LabelEncoder()
le.fit(df['class'])
df['class']= le.transform(df['class'])
X_train, X_test, y_train, y_test = train_test_split(df['size'], df['class'], random_state =42, test_size =0.33)
linreg =LinearRegression()
linreg.fit(X_train, y_train)
linreg.score(x_test,y_test)---------------------------------------------------------------------------ValueErrorTraceback(most recent call last)<ipython-input-9-f740a0daa981>in<module>12 X_train, X_test, y_train, y_test = train_test_split(df['size'], df['class'], random_state =42, test_size =0.33)13 linreg =LinearRegression()--->14 linreg.fit(X_train, y_train)15 linreg.score(x_test,y_test)~\anaconda3\lib\site-packages\sklearn\linear_model\_base.py in fit(self, X, y, sample_weight)490 n_jobs_ = self.n_jobs
491 X, y = check_X_y(X, y, accept_sparse=['csr','csc','coo'],-->492 y_numeric=True, multi_output=True)493494if sample_weight isnotNone:~\anaconda3\lib\site-packages\sklearn\utils\validation.py in check_X_y(X, y, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator)753 ensure_min_features=ensure_min_features,754 warn_on_dtype=warn_on_dtype,-->755 estimator=estimator)756if multi_output:757 y = check_array(y,'csr', force_all_finite=True, ensure_2d=False,~\anaconda3\lib\site-packages\sklearn\utils\validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)554"Reshape your data either using array.reshape(-1, 1) if "555"your data has a single feature or array.reshape(1, -1) "-->556"if it contains a single sample.".format(array))557558# in the future np.flexible dtypes will be handled like object dtypesValueError:Expected2D array, got 1D array instead:
array=[50100200].
السؤال
Meezo ML
عند محاولة تدريب model ( نموذج ) يظهر لي الخطأ التالي Expected 2D array, got 1D array instead الكود:
1 جواب على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.