如何预测下一个结果?

问题描述 投票:0回答:0

我做了一个程序来预测变量的结果。该程序运行良好。

代码如下:

#Import required libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import warnings

from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import train_test_split
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import GridSearchCV
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.metrics import accuracy_score

# I KNOW THAT I HAVE Categorical DATA 

def label_encoder(y):
   le = LabelEncoder()
   data[y] = le.fit_transform(data[y])

label_list = ["BET","Classe", "Anterior", "M3", "M5"]

for l in label_list:
    label_encoder(l)

X = data.drop(["Classe"],axis=1)
y = data['Classe']

X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,
                                           random_state=42, shuffle=True) 

y_train = y_train.values.reshape(-1,1)
y_test = y_test.values.reshape(-1,1)

sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.fit_transform(X_test)

dtc = DecisionTreeClassifier(random_state = 42)
accuracies = cross_val_score(dtc, X_train, y_train, cv=5)
dtc.fit(X_train,y_train)
y_pred = dtc.predict(X_test)

现在,问题。我的 CSV 文件有 1000 个结果。我想知道结果1001、1002、.....的预测

我试过这样的事情:

X_FUTURE = 10
predictions = np.array([])
last = y_test[-1]
for i in range(X_FUTURE):
  curr_prediction = dtc.predict(np.array([last]))
  print(curr_prediction)
  last = np.concatenate([last[1:], curr_prediction])
  predictions = np.concatenate([predictions, curr_prediction[0]])
predictions = scaler.inverse_transform([predictions])[0]
print(predictions)

不工作。有什么建议吗?

如果有帮助,我使用这篇文章作为基础。

非常感谢!

python machine-learning scikit-learn decision-tree
© www.soinside.com 2019 - 2024. All rights reserved.