是,尝试使用 scikit-learn 在我的训练集中训练模型,但出现此错误:
ValueError: Expected 2D array, got 1D array instead: array=[90. 4.].
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.
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X,y, test_size = 0.4, random_state = 4)
X_train = X_train.shape
X_test = X_test.shape
print(X_train)
print(X_test)
y_train = y_train.shape
y_test = y_test.shape
print(y_train)
print(y_test)
logR = LogisticRegression()
logR = logR.fit(X_train, y_train)
答案 0 :(得分:0)
您似乎正在按其形状替换数据点:
X_train = X_train.shape
X_test = X_test.shape
y_train = y_train.shape
y_test = y_test.shape
删除这些行,然后重新运行。
答案 1 :(得分:0)
您做了出色的工作,但做错了一件事情:您将火车和测试数据的形状替换为1D,这就是为什么您会遇到此错误的原因
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
String result =
IntStream.range(1, Math.min(n, 100)).mapToObj(x ->
{
if (x % 5 == 0) {
switch (x % 3) {
case 2:
return "Bus";
case 1:
return "bUs";
case 0:
return "buS";
}
}
return x + "";
}
).collect(Collectors.joining(", "));
System.out.println(result);
}
}