# 考虑增加某个计数,会不会提高socre import numpy as np from sklearn.linear_model import LinearRegression # from sklearn.metrics import mean_squared_error file_soft = "/home/maillee/chip_temp_predict/data_handle/ftc_to_select_event/soft_event_ftc.xlsx" file_hard = "/home/maillee/chip_temp_predict/data_handle/ftc_to_select_event/hard_event_ftc.xlsx" file_hard_cache = "/home/maillee/chip_temp_predict/data_handle/ftc_to_select_event/hard_cahce_event_ftc.xlsx" pd_data_soft = pd.read_excel(file_soft,index_col=0) pd_data_hard = pd.read_excel(file_hard,index_col=0) pd_data_hard_cache = pd.read_excel(file_hard_cache,index_col=0) pd_y = pd_data_hard_cache['cores-power'] not_selected_event = ['branch-misses','bus-cycles','cache-misses','instructions', 'ref-cycles','L1-dcache-load-misses', 'L1-dcache-stores','L1-icache-load-misses', 'LLC-load-misses','LLC-store-misses','LLC-stores', 'branch-load-misses','dTLB-load-misses','dTLB-loads', 'dTLB-store-misses','dTLB-stores','iTLB-load-misses', 'iTLB-loads','node-load-misses','node-loads','node-store-misses', 'node-stores','alignment-faults','bpf-output','cgroup-switches', 'cpu-migrations','dummy','emulation-faults','major-faults','minor-faults', 'page-faults','task-clock',] count =0 pd_x = pd.concat([pd_data_hard,pd_data_hard_cache,pd_data_soft],axis=1,join='outer') for i in not_selected_event: count = count+1 pd_x =pd.concat(pd_x[i],pd_x[['cpu-clock','context-switches', 'branch-instructions','cpu-cycles','cache-references', 'L1-dcache-loads','LLC-loads','branch-loads']],axis=1,join='outer') model = LinearRegression().fit(pd_x, pd_y) # print(model.score(pd_x,pd_y)) #R2 score y_pred = model.predict(pd_x) # plt.plot(y_pred) # plt.plot(pd_y) mse = mean_squared_error(pd_y, y_pred) print(count,i,model.score(pd_x,pd_y), mse,'\n') woatis wring
时间: 2023-12-22 07:06:42 浏览: 35
代码中存在语法错误,具体来说,是在 for 循环中的 pd.concat() 方法的调用中出现了问题。你需要将代码修改为以下形式:
```
for i in not_selected_event:
count = count+1
pd_x = pd.concat([pd_x[i],pd_x[['cpu-clock','context-switches',
'branch-instructions','cpu-cycles','cache-references',
'L1-dcache-loads','LLC-loads','branch-loads']]],axis=1,join='outer')
model = LinearRegression().fit(pd_x, pd_y)
y_pred = model.predict(pd_x)
mse = mean_squared_error(pd_y, y_pred)
print(count,i,model.score(pd_x,pd_y), mse,'\n')
```
这样,代码应该就可以正常运行了。
相关问题
import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression from sklearn import metrics import matplotlib.pyplot as plt
这段代码导入了 pandas、numpy、scikit-learn 和 matplotlib.pyplot 库中的一些常用模块和函数。
- `import pandas as pd` 导入了 pandas 库,并将其重命名为 pd,用于数据处理和分析。
- `import numpy as np` 导入了 numpy 库,并将其重命名为 np,用于数值计算和数组操作。
- `from sklearn.model_selection import train_test_split` 导入了 scikit-learn 库中的 train_test_split 函数,用于将数据集拆分为训练集和测试集。
- `from sklearn.linear_model import LogisticRegression` 导入了 scikit-learn 库中的逻辑回归模型(LogisticRegression),用于进行分类任务。
- `from sklearn import metrics` 导入了 scikit-learn 库中的 metrics 模块,用于评估模型性能。
- `import matplotlib.pyplot as plt` 导入了 matplotlib 库中的 pyplot 模块,并将其重命名为 plt,用于绘制数据可视化图形。
这段代码的目的是导入所需的库和模块,以便在后续的代码中使用它们进行数据处理、模型训练和评估以及结果可视化等操作。
解释如下代码:import numpy as np import matplotlib.pyplot as plt from sklearn.linear_model import LinearRegression from sklearn.datasets import make_regression from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler from sklearn.metrics import mean_squared_error
这段代码是导入了一些 Python 的第三方库,其作用如下:
1. `numpy`:Python 数组计算库,提供了高效的数组运算功能。
2. `matplotlib.pyplot`:Python 绘图库,用于绘制图形和数据可视化。
3. `sklearn.linear_model`:Scikit-Learn 库中的线性回归模型。
4. `sklearn.datasets`:Scikit-Learn 库中的数据集生成工具。
5. `sklearn.model_selection`:Scikit-Learn 库中的模型选择工具,用于数据集的分割、交叉验证等操作。
6. `sklearn.preprocessing`:Scikit-Learn 库中的数据预处理工具,用于数据标准化、归一化等操作。
7. `sklearn.metrics`:Scikit-Learn 库中的性能评估工具,用于计算模型的性能指标,如均方误差等。
这些库都是数据分析和机器学习中常用的工具,可以帮助我们更加方便地进行数据处理和模型构建。