多项式拟合曲线
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | # import pandas as pd # import numpy as np # from sklearn.preprocessing import PolynomialFeatures # from sklearn.linear_model import LinearRegression # import matplotlib.pyplot as plt # # Read the data from the Excel file # data = pd.read_excel(r'E:\\孙晓宇\\测试钞A1~E7共62开\\测试钞_磁扫特征统计结果\\combine.xlsx') # # print(data.iloc[0]) # # Define the dependent variable # y= data['平均值'] # # Define the independent variables # X = data[['油墨类型','BLOCK_width', 'width_ratio', 'BLOCK_depth','BLOCK_carval','BLOCK_angle','类型']] # # generate polynomial features of degree 2 # poly = PolynomialFeatures(degree=2, include_bias=True) # X_poly = poly.fit_transform(X) # # fit a linear regression model on the polynomial features # model = LinearRegression().fit(X_poly, y) # # use the model to make predictions for the new set of independent variables # predictions = model.predict(X_poly) # # print the predicted values # print(predictions) import pandas as pd import numpy as np from sklearn.preprocessing import PolynomialFeatures from sklearn.linear_model import LinearRegression import matplotlib.pyplot as plt # Read the data from the Excel file data = pd.read_excel(r 'E:\\孙晓宇\\测试钞A1~E7共62开\\测试钞_磁扫特征统计结果\\combine.xlsx' ) # print(data.iloc[0]) # Define the dependent variable y = data[ '标准差' ] # Define the independent variables X = data[[ '油墨类型' , 'BLOCK_width' , 'width_ratio' , 'BLOCK_depth' , 'BLOCK_carval' , 'BLOCK_angle' , '类型' ]] # generate polynomial features of degree 2 poly = PolynomialFeatures(degree = 10 , include_bias = True ) X_poly = poly.fit_transform(X) # fit a linear regression model on the polynomial features model = LinearRegression().fit(X_poly, y) # use the model to make predictions for the new set of independent variables predictions = model.predict(X_poly) # print the predicted values print (predictions) # calculate the residual errors residuals = y - predictions # plot the predicted values against the actual values plt.scatter(y, predictions) # plot a horizontal line at y=0 to show the line of perfect prediction plt.plot([ min (y), max (y)], [ min (y), max (y)], 'k--' , lw = 2 ) # plot the residual errors as a scatter plot plt.scatter(y, residuals, c = 'r' , s = 10 , alpha = 0.5 ) # add axis labels and a title plt.xlabel( 'Actual values' ) plt.ylabel( 'Predicted values' ) plt.title( 'Prediction error' ) # show the plot plt.show() |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
2019-04-18 tf调试函数