Я хочу запустить Logisti c Регрессию, чтобы предсказать жанр фильмов в этом наборе данных: movies.csv
Это код, который я использую:
from datascience import *
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
import numpy as np
movies = Table.read_table('movies.csv')
features=["marri", "huh", "hous", "mother", "nice", "home", "miss", "play", "happi", "write","power", "captain", "ship", "weve", "move", "ship", "system", "world", "command", "three"]
training_proportion = 17/20
num_movies = movies.num_rows
num_train = int(num_movies * training_proportion)
num_test = num_movies - num_train
train_movies = movies.take(np.arange(num_train))
test_movies = movies.take(np.arange(num_train, num_movies))
train_20 = train_movies.select(features)
test_20 = test_movies.select(features)
model = LogisticRegression()
## The target column is the genre
predicted_genre=movies.column("Genre")
model.fit(train_20, predicted_genre)
predicted_classes = model.predict(predicted_genre)
accuracy = accuracy_score(predicted_genre.flatten(),predicted_classes)
parameters = model.coef_
parameters
Однако этот код выдает следующую ошибку:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-4-95d9b3b0fe68> in <module>
19 ## The target column is the genre
20 predicted_genre=movies.column("Genre")
---> 21 model.fit(train_20, predicted_genre)
22 predicted_classes = model.predict(predicted_genre)
23 accuracy = accuracy_score(predicted_genre.flatten(),predicted_classes)
/srv/app/venv/lib/python3.6/site-packages/sklearn/linear_model/logistic.py in fit(self, X, y, sample_weight)
1530
1531 X, y = check_X_y(X, y, accept_sparse='csr', dtype=_dtype, order="C",
-> 1532 accept_large_sparse=solver != 'liblinear')
1533 check_classification_targets(y)
1534 self.classes_ = np.unique(y)
/srv/app/venv/lib/python3.6/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)
717 ensure_min_features=ensure_min_features,
718 warn_on_dtype=warn_on_dtype,
--> 719 estimator=estimator)
720 if multi_output:
721 y = check_array(y, 'csr', force_all_finite=True, ensure_2d=False,
/srv/app/venv/lib/python3.6/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)
494 try:
495 warnings.simplefilter('error', ComplexWarning)
--> 496 array = np.asarray(array, dtype=dtype, order=order)
497 except ComplexWarning:
498 raise ValueError("Complex data not supported\n"
/srv/app/venv/lib/python3.6/site-packages/numpy/core/numeric.py in asarray(a, dtype, order)
536
537 """
--> 538 return array(a, dtype, copy=False, order=order)
539
540
ValueError: invalid __array_struct__
Кроме того, появляется следующее предупреждение:
/srv/app/venv/lib/python3.6/site-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
FutureWarning)
/srv/app/venv/lib/python3.6/site-packages/datascience/tables.py:193: FutureWarning: Implicit column method lookup is deprecated.
warnings.warn("Implicit column method lookup is deprecated.", FutureWarning)
/srv/app/venv/lib/python3.6/site-packages/datascience/tables.py:193: FutureWarning: Implicit column method lookup is deprecated.
warnings.warn("Implicit column method lookup is deprecated.", FutureWarning)
Как мне нужно изменить код, чтобы получить это работает? Спасибо за вашу помощь!