from sklearn import preprocessing
import random
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
from sklearn import preprocessing
from datetime import datetime
import time
import math
from matplotlib import pyplot
from sklearn.model_selection import train_test_split
from scipy import stats, integrate
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import KFold
from sklearn.metrics import classification_report
from sklearn.model_selection import learning_curve
from sklearn.model_selection import validation_curve
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA
from sklearn.metrics import confusion_matrix
from sklearn.model_selection import train_test_split
from sklearn import metrics
from sklearn.svm import SVR
from sklearn.neighbors import KNeighborsRegressor
from sklearn.metrics import mean_squared_error, mean_absolute_error # 评价指标
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestRegressor
from sklearn.ensemble import AdaBoostRegressor
from xgboost import XGBRegressor
from sklearn.ensemble import GradientBoostingRegressor
from lightgbm import LGBMRegressor
from date_process import data_read_csv
train_x,train_y=data_read_csv()
x_train, x_test, y_train, y_test = train_test_split(np.array(train_x), np.array(train_y), test_size=0.4,shuffle=True,random_state=1)
twox_train, twox_test, twoy_train, twoy_test = train_test_split(np.array(x_test), np.array(y_test), test_size=0.5,shuffle=True,random_state=1)
print('x_train.shape',x_train.shape)
print('x_test.shape',x_test.shape)
# 集成学习模型
# svm算法
from sklearn.linear_model import LassoLarsIC as LR#逻辑回归
svm = LR(max_iter=5,fit_intercept=False,copy_X=False)
svm.fit(twox_train, twoy_train)
svm_pred = svm.predict(twox_test)
from metra import metric
mae, mse, rmse, mape, mspe,r2=metric(np.array(svm_pred), np.array(twoy_test))
print('mae, mse, rmse, mape, mspe,r2')
print(mae, mse, rmse, mape, mspe,r2)
# 设置Seaborn样式
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="darkgrid")
x = range(len(twoy_test))
data = pd.DataFrame({'x': x, 'y_pred': svm_pred, 'y_true': twoy_test}).iloc[100:200,:]
# 绘制y_pred的折线图
sns.lineplot(x='x', y='y_pred', data=data, linewidth=1, label='y_pred')
# 绘制y_true的折线图
sns.lineplot(x='x', y='y_true', data=data, linewidth=1, label='y_true')
# 添加标题和标签
plt.title('Prediction vs True')
plt.xlabel('Date')
plt.ylabel('Values')
plt.savefig('transformer10预测1.png')
# 显示图形
plt.show()
逻辑回归分析
原创
©著作权归作者所有:来自51CTO博客作者奇点_python_nlp的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:基于机器学习的疾病预测实战
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
nanoDLA逻辑分析仪上手教程
逻辑分析仪分析自定义总线数据
逻辑分析仪 nanoDLA 调试 i2c -
python 手写逻辑回归 python逻辑回归分析
一、python逻辑回归简单案例1. 加载相关库2. 构造数据和特征,并查看散点图
机器学习 数据 数据集 python -
CentOS svn需要开放哪些端口
svn add values/strings.xml //--添加 svn st //--查看状态 svn ci //--提交 svn ci -m "svn ci,
CentOS svn需要开放哪些端口 svn linux path 工作