Quantcast
Channel: Форум программистов и сисадминов Киберфорум
Viewing all articles
Browse latest Browse all 517363

Выдаёт ошибку, не могу найти проблему - Python

$
0
0
Полдня сижу и не могу понять в чем дело, пытаюсь сделать логистическую регрессию.


:


from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split, GridSearchCV, cross_val_score, RepeatedStratifiedKFold, StratifiedKFold
from sklearn.metrics import accuracy_score, confusion_matrix,roc_curve, roc_auc_score, precision_score, recall_score, precision_recall_curve
from sklearn.metrics import f1_score

normalized_df_reg = LogisticRegression().fit(x_train, y_train)
normalized_df_reg_pred = normalized_df_reg.predict(x_test)

acc = accuracy_score(y_test, normalized_df_reg_pred)
print(f"The accuracy score for Logreg is: {round(acc,3)*100}%")

f1 = fl_score(y_test, normalized_df_reg_pred)
print(f"The f1 score for LogReg is: {round(f1,3)*100}%")

precision = precision_score(y_test, normalized_df_reg_pred)
print(f"The precision score for Logkeg is: {round(precision,3)*100}%")

recall = recall_score(y_test, normalized_df_reg_pred)
print(f"The recall score for Logkeg is: {round(recall,3)*100}%")

вот ошибка:
ValueError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_14800/91225549.py in <module>
4 from sklearn.metrics import f1_score
5
----> 6 normalized_df_reg = LogisticRegression().fit(x_train, y_train)
7 normalized_df_reg_pred = normalized_df_reg.predict(x_test)
8

~\anaconda3\lib\site-packages\sklearn\linear_model\_logistic.py in fit(self, X, y, sample_weight)
1342 _dtype = [np.float64, np.float32]
1343
-> 1344 X, y = self._validate_data(X, y, accept_sparse='csr', dtype=_dtype,
1345 order="C",
1346 accept_large_sparse=solver != 'liblinear')

~\anaconda3\lib\site-packages\sklearn\base.py in _validate_data(self, X, y, reset, validate_separately, **check_params)
431 y = check_array(y, **check_y_params)
432 else:
--> 433 X, y = check_X_y(X, y, **check_params)
434 out = X, y
435

~\anaconda3\lib\site-packages\sklearn\utils\validation.py in inner_f(*args, **kwargs)
61 extra_args = len(args) - len(all_args)
62 if extra_args <= 0:
---> 63 return f(*args, **kwargs)
64
65 # extra_args > 0

~\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, estimator)
869 raise ValueError("y cannot be None")
870
--> 871 X = check_array(X, accept_sparse=accept_sparse,
872 accept_large_sparse=accept_large_sparse,
873 dtype=dtype, order=order, copy=copy,

~\anaconda3\lib\site-packages\sklearn\utils\validation.py in inner_f(*args, **kwargs)
61 extra_args = len(args) - len(all_args)
62 if extra_args <= 0:
---> 63 return f(*args, **kwargs)
64
65 # extra_args > 0

~\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, estimator)
692 # If input is 1D raise error
693 if array.ndim == 1:
--> 694 raise ValueError(
695 "Expected 2D array, got 1D array instead:\narray={}.\n"
696 "Reshape your data either using array.reshape(-1, 1) if "

ValueError: Expected 2D array, got 1D array instead:
array=[7. 2. 1. 2. 1. 2. 1. 2. 1. 5. 7. 2. 2. 1. 1. 2. 7. 3. 6. 7. 2. 2. 1. 1.
6. 3. 2. 6. 3. 2. 2. 1. 1. 1. 3. 2. 7. 2. 2. 7. 1. 1. 1. 2. 2. 2. 3. 1.
1. 2. 2. 7. 2. 2. 2. 2. 1. 5. 7. 2. 1. 2. 2. 7. 1. 1. 6. 6. 1. 1. 2. 7.
5. 1. 2. 2. 2. 1. 2. 2. 7. 1. 7. 2. 7. 1. 1. 2. 1. 2. 2. 2. 2. 2. 1. 2.
7. 1. 1. 2. 6. 2. 1. 1. 1. 2. 7. 3. 1. 7. 3. 6. 1. 1. 7. 1. 7. 1. 7. 2.
1. 5. 2. 2. 1. 1. 2. 2. 1. 2. 1. 7. 1. 2. 1. 1. 1. 3. 1. 3. 1. 1. 2. 5.
2. 1. 1. 1. 3. 1. 5. 2. 1. 2. 5. 1. 3. 3. 1. 3. 7. 2. 2. 3. 2. 2. 2. 1.
1. 2. 7.].
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.

Вложения
Тип файла: rar Архив WinRAR.rar (7.3 Кб)

Viewing all articles
Browse latest Browse all 517363

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>