2019118_四个化学数据分析(3)

import pandas as pd
from pylab import mpl
mpl.rcParams['font.sans-serif'] = ['FangSong'] # 指定默认字体
mpl.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题
import matplotlib.pyplot as plt
%matplotlib inline
test=pd.read_excel('数据.xlsx')
test.head()
温度/℃0.0010.0050.010.020.040.060.080.10.5
001.00021.00021.00021.00021.00021.00021.00021.00021.0000
120135.23001.00171.00171.00171.00171.00171.00171.00171.0015
240144.470028.86001.00781.00781.00781.00781.00781.00781.0076
360153.710030.710015.34001.07101.07101.07101.07101.07101.0169
480162.950032.570016.27008.11904.04401.02921.02921.02921.0290
test.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 35 entries, 0 to 34
Data columns (total 10 columns):
温度/℃     35 non-null int64
0.001    35 non-null float64
0.005    35 non-null float64
0.01     35 non-null float64
0.02     35 non-null float64
0.04     35 non-null float64
0.06     35 non-null float64
0.08     35 non-null float64
0.1      35 non-null float64
0.5      35 non-null float64
dtypes: float64(9), int64(1)
memory usage: 2.8 KB
test.hist(figsize=(20,10))
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x0000026E87C47BA8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x0000026E87CB1550>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x0000026E87CCBBE0>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x0000026E87CFD278>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x0000026E87D22908>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x0000026E87D22940>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x0000026E87D7F668>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x0000026E87DA6CF8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x0000026E87DD93C8>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x0000026E87E01A58>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x0000026E87E33128>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x0000026E87E5B7B8>]],
      dtype=object)

在这里插入图片描述
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-niQ1ySLM-1574997331548)(output_4_1.png)]

预测温度/℃

y = test['温度/℃']
X = test.drop(['温度/℃'],axis=1)
print('data shape: {0}; no. positive: {1}; no. negative: {2}'.format(
    X.shape, y[y==1].shape[0], y[y==0].shape[0]))
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1)
data shape: (35, 9); no. positive: 0; no. negative: 1

基于xgboost的预测算法

from sklearn import linear_model
model =XGBRegressor(max_depth = 2)
model.fit(X_train, y_train)
train_score = model.score(X_train, y_train)
test_score = model.score(X_test, y_test)
print('train score: {train_score:.6f}; test score: {test_score:.6f}'.format(
    train_score=train_score, test_score=test_score))
D:\anaconda\lib\site-packages\xgboost\core.py:587: FutureWarning: Series.base is deprecated and will be removed in a future version
  if getattr(data, 'base', None) is not None and \


[20:26:54] WARNING: C:/Jenkins/workspace/xgboost-win64_release_0.90/src/objective/regression_obj.cu:152: reg:linear is now deprecated in favor of reg:squarederror.
train score: 0.999972; test score: 0.990900
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值