-
Notifications
You must be signed in to change notification settings - Fork 109
Description
ciao,
seguendo il corso, una volta attivato a questo punto,
from sklearn.preprocessing import PolynomialFeatures polyfeats = PolynomialFeatures(degree = 2) X_train_poly = polyfeats.fit_transform(X_train) X_test_poly = polyfeats.transform(X_test)
mi dà tale errore
`ValueError Traceback (most recent call last)
in
1 from sklearn.preprocessing import PolynomialFeatures
2 polyfeats = PolynomialFeatures(degree = 2)
----> 3 X_train_poly = polyfeats.fit_transform(X_train)
4 X_test_poly = polyfeats.transform(X_test)
~\Anaconda3\lib\site-packages\sklearn\base.py in fit_transform(self, X, y, **fit_params)
551 if y is None:
552 # fit method of arity 1 (unsupervised transformation)
--> 553 return self.fit(X, **fit_params).transform(X)
554 else:
555 # fit method of arity 2 (supervised transformation)
~\Anaconda3\lib\site-packages\sklearn\preprocessing\data.py in fit(self, X, y)
1463 self : instance
1464 """
-> 1465 n_samples, n_features = check_array(X, accept_sparse=True).shape
1466 combinations = self._combinations(n_features, self.degree,
1467 self.interaction_only,
~\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)
519 "Reshape your data either using array.reshape(-1, 1) if "
520 "your data has a single feature or array.reshape(1, -1) "
--> 521 "if it contains a single sample.".format(array))
522
523 # in the future np.flexible dtypes will be handled like object dtypes
ValueError: Expected 2D array, got 1D array instead:
array=[34.41 7.73 16.96 4.97 17.93 18.72 13.09 21.02 26.45 10.26 4.59 5.25
8.05 12.79 7.7 7.22 7.79 16.35 4.38 24.91 14.65 5.5 13.34 21.78
15.1 21.14 11.66 9.43 16.23 14.52 9.8 11.64 18.66 5.08 9.5 5.99
4.45 16.22 23.98 11.25 5.7 11.5 3.16 6.21 9.5 14.13 5.98 3.01
8.16 11.69 7.26 6.62 27.8 6.43 14.1 5.9 10.58 12.14 6.53 9.54
18.05 10.24 11.72 24.08 24.16 7.67 15.17 4.03 20.08 21.46 14.67 16.65
9.25 13.27 22.6 10.45 6.36 13.44 19.01 7.9 10.11 3.53 12.04 11.1
19.52 14.37 8.1 16.21 5.29 6.36 10.29 16.9 5.1 5.49 9.45 27.26
7.85 20.34 34.37 21.24 17.16 2.47 15.03 18.35 7.01 9.55 14.44 4.56
6.59 9.51 17.92 7.54 9.68 23.79 11.98 7.12 10.53 16.94 9.69 17.28
21.32 6.27 16.14 9.74 23.6 21.32 16.03 12.33 8.05 5.98 5.57 9.47
22.88 5.39 29.55 2.88 8.05 6.9 8.1 16.3 13.51 7.6 18.34 10.16
3.7 14.1 29.97 1.98 3.53 14.19 9.1 18.33 10.36 8.26 7.14 36.98
14.33 3.92 1.73 7.51 5.64 13.11 13. 21.45 12.12 6.58 7.18 15.55
23.34 18.46 4.73 9.59 10.19 15.94 9.67 22.98 9.52 7.83 17.11 11.28
9.97 7.39 13.65 3.13 15.17 2.94 4.5 14.81 3.76 12.93 10.27 13.98
17.21 10.42 2.98 10.4 16.59 4.82 16.74 5.29 7.53 7.79 13.27 13.44
12.86 14.79 11.41 14.98 6.86 4.84 13. 13.45 23.09 20.31 20.32 15.7
25.41 9.93 6.73 21.08 12.6 6.68 19.88 7.44 16.44 4.98 7.43 3.26
12.03 3.57 5.89 6.93 12.01 6.92 3.73 3.11 10.59 12.87 6.65 18.13
11.32 8.79 8.93 30.81 5.49 34.77 19.92 18.06 4.85 6.36 28.32 26.42
6.75 7.56 17.6 12.26 18.71 6.48 5.91 6.12 3.81 9.62 14.27 18.06
22.11 17.15 16.42 30.63 8.2 6.72 7.44 13.61 11.48 3.56 3.95 24.39
6.87 5.12 23.24 17.27 5.81 16.47 30.62 16.29 6.58 17.44 10.13 20.85
8.43 15.02 18.85 15.39 3.33 12.8 5.68 2.96 3.32 13.28 12.5 3.11
13.04 27.71 17.19 13.15 18.68 19.31 7.6 23.29 30.59 13.99 29.53 8.23
29.68 6.29 6.19 8.51 18.13 19.69 8.01 8.61 5.19 13.22 15.76 27.38
10.45 5.52 5.68 16.51 9.81 10.56 23.97 9.64 13.35 4.32 5.03 9.28
19.37 5.5 14.36 6.72 8.44 4.7 11.22 4.16 23.98 17.1 12.67 2.97
3.59 11.74 2.87 10.3 18.8 14.69].
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.`
riusciresti a spiegarmi, grazie mille