├── README.md └── 黑龙江大豆单产因素研究所用模型 .ipynb /README.md: -------------------------------------------------------------------------------- 1 | 本代码共包含6个模型,分别是LDA模型、ols回归模型、方差膨胀因子(VIF)、 Pearson相关系数、Elastic-Net回归模型和R方检验。代码中所提及的数据集,请联系作者获取 2 | -------------------------------------------------------------------------------- /黑龙江大豆单产因素研究所用模型 .ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"E53FE31EF1E64B29AC7DDF7E6B69503D","notebookId":"661cf2e1d60ce3fe5bf37cc2","runtime":{"status":"default","execution_status":null,"is_visible":false},"jupyter":{},"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"}},"source":"## 构建LDA模型"},{"cell_type":"markdown","metadata":{"id":"F7ED233053844A9C85CF1B5B4F9D502D","notebookId":"661cf2e1d60ce3fe5bf37cc2","runtime":{"status":"default","execution_status":null,"is_visible":false},"jupyter":{},"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"}},"source":"*1、去除句子停用词,用于生产句子分词*"},{"cell_type":"code","metadata":{"id":"11DFC338DA35444494C9D89591BA98F7","notebookId":"661cf2e1d60ce3fe5bf37cc2","jupyter":{},"collapsed":false,"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"},"trusted":true},"source":"'''\n用于生成句子分词\n'''\nimport re\nimport jieba as jb\ndef stopwordslist(filepath):\n stopwords = [line.strip() for line in open(filepath, 'r', encoding='utf-8').readlines()]\n return stopwords\n\n# 对句子进行分词\ndef seg_sentence(sentence):\n sentence = re.sub(u'[0-9\\.]+', u'', sentence)\n #jb.add_word('词汇')\t\t# 这里是加入自定义的词来补充jieba词典\n sentence_seged = jb.cut(sentence.strip())\n stopwords = stopwordslist('/home/mw/input/soybean_policy2266/cn_stopwords.txt') # 这里加载停用词的路径\n outstr = ''\n for word in sentence_seged:\n if word not in stopwords and word.__len__()>1:\n if word != '\\t':\n outstr += word\n outstr += \" \"\n return outstr\n\n\ninputs = open(r\"/home/mw/input/soybean_policy2266/大豆政策.txt\", 'r', encoding='utf-8')\n\noutputs = open(r\"/home/mw/input/soybean_policy2266/大豆政策_分词.txt\", 'w',encoding='utf-8')\nfor line in inputs:\n line_seg = seg_sentence(line) # 这里的返回值是字符串\n outputs.write(line_seg + '\\n')\noutputs.close()\ninputs.close()\n","outputs":[{"output_type":"stream","name":"stderr","text":"<>:12: DeprecationWarning: invalid escape sequence '\\.'\n<>:12: DeprecationWarning: invalid escape sequence '\\.'\n/tmp/ipykernel_67/1713476716.py:12: DeprecationWarning: invalid escape sequence '\\.'\n sentence = re.sub(u'[0-9\\.]+', u'', sentence)\n"}],"execution_count":49},{"cell_type":"markdown","metadata":{"id":"C2910102B9BF4202B9EDF729FC6FAEB1","notebookId":"661cf2e1d60ce3fe5bf37cc2","runtime":{"status":"default","execution_status":null,"is_visible":false},"jupyter":{},"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"}},"source":"*2、构建LDA模型*"},{"cell_type":"code","metadata":{"id":"426DC31FA0B641F08F3E2C17B36A5906","notebookId":"661cf2e1d60ce3fe5bf37cc2","jupyter":{},"collapsed":false,"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"},"trusted":true},"source":"import codecs\nfrom gensim import corpora\nfrom gensim.models import LdaModel\nfrom gensim.corpora import Dictionary\n\n\ntrain = []\n\nfp = codecs.open(r\"/home/mw/input/soybean_policy2266/大豆政策_分词.txt\",'r',encoding='utf8')\nfor line in fp:\n if line != '':\n line = line.split()\n train.append([w for w in line])\n\ndictionary = corpora.Dictionary(train)\n\ncorpus = [dictionary.doc2bow(text) for text in train]\n\nlda = LdaModel(corpus=corpus, id2word=dictionary, num_topics=4, passes=100)\n# num_topics:主题数目\n# passes:训练伦次\n# num_words:每个主题下输出的term的数目\n\nfor topic in lda.print_topics(num_words = 20):\n termNumber = topic[0]\n print(topic[0], ':', sep='')\n listOfTerms = topic[1].split('+')\n for term in listOfTerms:\n listItems = term.split('*')\n print(' ', listItems[1], '(', listItems[0], ')', sep='')\n","outputs":[{"output_type":"stream","name":"stdout","text":"0:\n \"大豆\" (0.048)\n \"发展\" ( 0.013)\n \"市场\" ( 0.013)\n \"生产\" ( 0.012)\n \"玉米\" ( 0.012)\n \"进口\" ( 0.010)\n \"引导\" ( 0.009)\n \"加强\" ( 0.009)\n \"合理\" ( 0.009)\n \"种植\" ( 0.009)\n \"统筹\" ( 0.007)\n \"优势\" ( 0.007)\n \"区域\" ( 0.007)\n \"轮作\" ( 0.007)\n \"信息\" ( 0.007)\n \"资源\" ( 0.006)\n \"调减\" ( 0.006)\n \"实现\" ( 0.006)\n \"发布\" ( 0.005)\n \"方式\"( 0.005)\n1:\n \"大豆\" (0.038)\n \"推进\" ( 0.010)\n \"生产\" ( 0.010)\n \"建设\" ( 0.009)\n \"发展\" ( 0.009)\n \"农田\" ( 0.008)\n \"农业\" ( 0.008)\n \"加强\" ( 0.008)\n \"加快\" ( 0.007)\n \"优势\" ( 0.006)\n \"供给\" ( 0.006)\n \"水平\" ( 0.006)\n \"国产\" ( 0.006)\n \"提高\" ( 0.006)\n \"高标准\" ( 0.006)\n \"发挥\" ( 0.006)\n \"成员\" ( 0.006)\n \"市场\" ( 0.006)\n \"地区\" ( 0.006)\n \"绿色\"( 0.005)\n2:\n \"大豆\" (0.062)\n \"生产\" ( 0.016)\n \"玉米\" ( 0.013)\n \"政策\" ( 0.013)\n \"轮作\" ( 0.012)\n \"补贴\" ( 0.011)\n \"农民\" ( 0.009)\n \"目标\" ( 0.009)\n \"提高\" ( 0.008)\n \"种植\" ( 0.008)\n \"技术\" ( 0.008)\n \"面积\" ( 0.008)\n \"力争\" ( 0.008)\n \"振兴\" ( 0.008)\n \"高产\" ( 0.008)\n \"一批\" ( 0.007)\n \"公斤\" ( 0.007)\n \"开展\" ( 0.007)\n \"增产\" ( 0.006)\n \"实施\"( 0.006)\n3:\n \"大豆\" (0.053)\n \"生产\" ( 0.015)\n \"发展\" ( 0.014)\n \"种植\" ( 0.012)\n \"玉米\" ( 0.011)\n \"支持\" ( 0.010)\n \"实施\" ( 0.009)\n \"重要\" ( 0.007)\n \"粮食\" ( 0.007)\n \"保险\" ( 0.007)\n \"资源\" ( 0.007)\n \"促进\" ( 0.007)\n \"推进\" ( 0.006)\n \"提升\" ( 0.006)\n \"补贴\" ( 0.006)\n \"农业\" ( 0.006)\n \"稳定\" ( 0.006)\n \"加大\" ( 0.006)\n \"保护\" ( 0.006)\n \"油料\"( 0.006)\n"}],"execution_count":52},{"cell_type":"markdown","metadata":{"id":"61DA9A09403945F9A44954D416AC5AED","notebookId":"661cf2e1d60ce3fe5bf37cc2","runtime":{"status":"default","execution_status":null,"is_visible":false},"jupyter":{},"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"}},"source":"*3、对划分好的主题进行可视化*"},{"cell_type":"code","metadata":{"id":"40D24E02633C45C8AF39BE45B771DB6F","notebookId":"661cf2e1d60ce3fe5bf37cc2","jupyter":{},"collapsed":false,"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"},"trusted":true,"hide_input":false},"source":"import codecs \nimport pyLDAvis.gensim\nfrom gensim import corpora \nfrom gensim.models import LdaModel # 确保LdaModel的L是小写 \nfrom gensim.corpora import Dictionary \n \n# 读取文本文件并构建语料库 \ntrain = [] \nwith codecs.open(r\"/home/mw/input/soybean_policy2266/大豆政策_分词.txt\", 'r', encoding='utf8') as fp: \n for line in fp: \n if line.strip() != '': # 使用strip()去除空白字符 \n train.append(line.split()) \n \n# 构建字典和语料库 \ndictionary = Dictionary(train) \ncorpus = [dictionary.doc2bow(text) for text in train] \n \n# 训练LDA模型 \nlda_model = LdaModel(corpus=corpus, id2word=dictionary, num_topics=4, passes=10) \n \n# 打印主题和关键词 \nfor idx, topic in lda_model.print_topics(-1): \n print('Topic: {} \\nWords: {}'.format(idx, topic)) \n \n# 准备LDA可视化 \n# 这里不需要做任何修改,但为了消除警告,我们可能需要更新pyLDAvis的版本或修改相关代码 \nlda_display = pyLDAvis.gensim.prepare(lda_model, corpus, dictionary) \n \n# 展示LDA可视化在notebook的output cell中 \npyLDAvis.display(lda_display)","outputs":[{"output_type":"stream","name":"stderr","text":"/opt/conda/lib/python3.6/site-packages/scipy/sparse/sparsetools.py:21: DeprecationWarning: `scipy.sparse.sparsetools` is deprecated!\nscipy.sparse.sparsetools is a private module for scipy.sparse, and should not be used.\n _deprecated()\n"},{"output_type":"stream","name":"stdout","text":"Topic: 0 \nWords: 0.008*\"贯彻\" + 0.008*\"十八\" + 0.008*\"精神\" + 0.007*\"战略\" + 0.006*\"总体\" + 0.006*\"发展\" + 0.004*\"统领\" + 0.004*\"五中全会\" + 0.004*\"四中\" + 0.004*\"产品安全\"\nTopic: 1 \nWords: 0.073*\"大豆\" + 0.021*\"生产\" + 0.014*\"发展\" + 0.009*\"资源\" + 0.008*\"提高\" + 0.008*\"加强\" + 0.007*\"引导\" + 0.007*\"市场\" + 0.006*\"力争\" + 0.006*\"进口\"\nTopic: 2 \nWords: 0.042*\"大豆\" + 0.018*\"玉米\" + 0.017*\"轮作\" + 0.013*\"种植\" + 0.012*\"实施\" + 0.012*\"开展\" + 0.010*\"黄淮海\" + 0.010*\"推进\" + 0.009*\"振兴\" + 0.008*\"农业\"\nTopic: 3 \nWords: 0.043*\"大豆\" + 0.016*\"补贴\" + 0.016*\"生产\" + 0.014*\"支持\" + 0.014*\"玉米\" + 0.012*\"种植\" + 0.011*\"政策\" + 0.010*\"发展\" + 0.010*\"稳定\" + 0.010*\"农民\"\n"},{"output_type":"stream","name":"stderr","text":"/opt/conda/lib/python3.6/site-packages/pyLDAvis/_prepare.py:387: DeprecationWarning: \n.ix is deprecated. Please use\n.loc for label based indexing or\n.iloc for positional indexing\n\nSee the documentation here:\nhttp://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n topic_term_dists = topic_term_dists.ix[topic_order]\n/opt/conda/lib/python3.6/site-packages/pyLDAvis/_prepare.py:257: FutureWarning: Sorting because non-concatenation axis is not aligned. A future version\nof pandas will change to not sort by default.\n\nTo accept the future behavior, pass 'sort=False'.\n\nTo retain the current behavior and silence the warning, pass 'sort=True'.\n\n return pd.concat([default_term_info] + list(topic_dfs))\n"},{"output_type":"execute_result","data":{"text/plain":"","text/html":"\n\n\n\n
\n"},"metadata":{},"execution_count":8}],"execution_count":8},{"cell_type":"markdown","metadata":{"id":"4964CAC2D20544ABAD07DDE34DA20479","notebookId":"661cf2e1d60ce3fe5bf37cc2","runtime":{"status":"default","execution_status":null,"is_visible":false},"jupyter":{},"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"}},"source":"## OLS模型"},{"cell_type":"code","metadata":{"id":"1D410DFA4FA14C75B1F9E4C92D47902B","notebookId":"661cf2e1d60ce3fe5bf37cc2","jupyter":{},"collapsed":false,"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"},"trusted":true},"source":"#导入包\nimport pandas as pd\nimport statsmodels.api as sm\n#读取文件\ndata = '/home/mw/input/soybean_zhibiao3569/确定指标.csv'\n# 使用正确的编码读取CSV文件\ndf = pd.read_csv(data, encoding='gbk')\nprint(df)\nprint(\"---------------------------------------------\")\nendog = df['大豆单位面积产量(千克/公顷)'] # 因变量\nexog = df[['成本利润率(%/亩)','净利润(元/亩)','每亩用工数量(日)',\n '土地成本(元/亩)','生产成本(元/亩)','人工成本(元/亩)',\n '农业生产指数(上年=100)','大豆进口数量(吨)','产值合计(元/亩)',\n '农村用电量(万千瓦时)','农作物受灾面积(千公顷)','乡村户数(万户)',\n '大豆播种面积(万公顷)','全国农业科技进步贡献率(%)']] # 自变量\n\n# 创建OLS模型并拟合\nmodel = sm.OLS(endog, exog).fit()\nprint(model.summary())\nprint(model.ssr)\n","outputs":[{"output_type":"stream","name":"stdout","text":" 年份 成本利润率(%/亩) 净利润(元/亩) 每亩化肥用量(公斤) 每亩种子用量(公斤) 农业机械总动力(万千瓦) \\\n0 2007 42.92 122.92 9.11 4.80 2785.3 \n1 2008 43.36 153.63 9.18 4.85 3018.4 \n2 2009 22.10 85.06 10.05 4.79 3401.3 \n3 2010 28.14 122.11 10.35 4.76 3736.3 \n4 2011 20.99 105.81 10.19 4.58 4097.8 \n5 2012 14.35 84.06 10.80 4.61 4549.3 \n6 2013 -4.00 -25.31 10.76 4.90 4848.7 \n7 2014 4.76 30.98 10.44 5.04 5155.5 \n8 2015 -20.63 -137.71 10.08 5.11 5442.7 \n9 2016 -38.78 -259.97 10.22 5.17 5634.3 \n10 2017 -19.86 -130.52 10.32 5.06 5813.8 \n11 2018 -29.28 -198.30 10.31 5.03 6082.4 \n12 2019 -36.31 -263.55 10.35 4.98 5273.5 \n13 2020 -17.61 -137.92 10.66 5.30 6775.1 \n14 2021 -4.05 -34.96 10.49 5.07 6888.4 \n\n 每亩用工数量(日) 土地成本(元/亩) 生产成本(元/亩) 人工成本(元/亩) 农业生产指数(上年=100) 大豆进口数量(吨) \\\n0 2.94 100.19 186.20 59.72 103.3 237947 \n1 2.51 126.23 228.11 60.42 112.7 424775 \n2 2.87 148.17 236.64 80.18 105.1 1884776 \n3 2.23 174.65 259.28 83.58 108.9 2502408 \n4 2.12 207.70 296.35 101.19 110.0 1967345 \n5 2.03 238.16 129.21 129.21 107.5 2081095 \n6 1.89 272.56 360.08 139.29 107.5 2907805 \n7 1.76 295.18 355.02 139.74 107.7 3458842 \n8 1.67 312.67 354.92 140.39 107.3 3326583 \n9 1.65 313.10 357.35 146.39 105.4 2992664 \n10 1.70 294.08 363.17 152.47 104.1 1939894 \n11 1.70 305.09 372.06 158.61 104.5 1602347 \n12 1.85 351.82 374.01 175.34 102.5 2297826 \n13 1.92 365.82 417.59 193.36 101.4 2067451 \n14 1.73 461.04 403.25 172.37 105.8 2665365 \n\n 产值合计(元/亩) 大豆单位面积产量(千克/公顷) 农村用电量(万千瓦时) 农作物受灾面积(千公顷) 乡村户数(万户) \\\n0 409.31 1138 410335 6653.0 493.9 \n1 507.97 1508 442525 2367.0 504.9 \n2 469.87 1470 484379 7394.0 509.5 \n3 556.04 1651 557278 1432.2 509.1 \n4 609.86 1759 701381 1536.8 512.5 \n5 669.68 1823 643269 2429.4 514.1 \n6 607.33 1722 669533 2734.1 517.7 \n7 681.18 1840 695625 810.0 520.5 \n8 529.88 1874 725812 1175.3 524.5 \n9 410.48 1746 774675 4223.7 521.3 \n10 526.73 1846 797667 1550.5 523.5 \n11 478.85 1844 828042 4155.0 530.8 \n12 462.28 1824 856368 3540.7 545.1 \n13 645.49 1905 897225 3178.5 545.5 \n14 829.33 1849 939945 831.5 518.2 \n\n 大豆播种面积(万公顷) 全国农业科技进步贡献率(%) \n0 397.9 48.0 \n1 414.8 49.0 \n2 416.5 51.0 \n3 372.7 52.0 \n4 340.2 53.5 \n5 286.0 54.5 \n6 263.7 55.2 \n7 279.3 55.6 \n8 266.1 56.1 \n9 322.3 56.7 \n10 373.5 57.5 \n11 356.8 58.3 \n12 427.9 59.2 \n13 483.2 60.7 \n14 388.8 61.5 \n---------------------------------------------\n OLS Regression Results \n==============================================================================\nDep. Variable: 大豆单位面积产量(千克/公顷) R-squared: 1.000\nModel: OLS Adj. R-squared: 1.000\nMethod: Least Squares F-statistic: 1.207e+06\nDate: Mon, 22 Apr 2024 Prob (F-statistic): 0.000713\nTime: 09:27:29 Log-Likelihood: -8.3160\nNo. Observations: 15 AIC: 44.63\nDf Residuals: 1 BIC: 54.54\nDf Model: 14 \nCovariance Type: nonrobust \n==================================================================================\n coef std err t P>|t| [0.025 0.975]\n----------------------------------------------------------------------------------\n成本利润率(%/亩) -17.3033 0.311 -55.600 0.011 -21.258 -13.349\n净利润(元/亩) -4.3566 0.208 -20.916 0.030 -7.003 -1.710\n每亩用工数量(日) -395.7609 11.476 -34.485 0.018 -541.583 -249.938\n土地成本(元/亩) -4.7411 0.165 -28.692 0.022 -6.841 -2.642\n生产成本(元/亩) -0.3462 0.011 -31.911 0.020 -0.484 -0.208\n人工成本(元/亩) -20.5881 0.446 -46.111 0.014 -26.261 -14.915\n农业生产指数(上年=100) -46.0013 1.135 -40.520 0.016 -60.426 -31.576\n大豆进口数量(吨) -5.681e-05 1.75e-06 -32.538 0.020 -7.9e-05 -3.46e-05\n产值合计(元/亩) 7.6290 0.181 42.080 0.015 5.325 9.933\n农村用电量(万千瓦时) 0.0004 2.09e-05 17.272 0.037 9.53e-05 0.001\n农作物受灾面积(千公顷) -0.0026 0.001 -2.426 0.249 -0.016 0.011\n乡村户数(万户) 18.9991 0.299 63.641 0.010 15.206 22.792\n大豆播种面积(万公顷) 0.5961 0.018 32.237 0.020 0.361 0.831\n全国农业科技进步贡献率(%) -57.5090 1.275 -45.092 0.014 -73.714 -41.304\n==============================================================================\nOmnibus: 0.573 Durbin-Watson: 2.272\nProb(Omnibus): 0.751 Jarque-Bera (JB): 0.624\nSkew: -0.293 Prob(JB): 0.732\nKurtosis: 2.190 Cond. No. 6.63e+07\n==============================================================================\n\nWarnings:\n[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n[2] The condition number is large, 6.63e+07. This might indicate that there are\nstrong multicollinearity or other numerical problems.\n2.6617096756684746\n"},{"output_type":"stream","name":"stderr","text":"/opt/conda/lib/python3.6/site-packages/scipy/stats/stats.py:1416: UserWarning: kurtosistest only valid for n>=20 ... continuing anyway, n=15\n \"anyway, n=%i\" % int(n))\n"}],"execution_count":3},{"cell_type":"markdown","metadata":{"id":"A834102DF507474CA4D5A5CC30EAEBAA","notebookId":"661cf2e1d60ce3fe5bf37cc2","runtime":{"status":"default","execution_status":null,"is_visible":false},"jupyter":{},"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"}},"source":"## 共线性"},{"cell_type":"code","metadata":{"id":"9DF5A34DBBB84308B421A029D27DF6FD","notebookId":"661cf2e1d60ce3fe5bf37cc2","jupyter":{},"collapsed":false,"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"},"trusted":true},"source":"#用的是vif膨胀因子\nimport pandas as pd\nimport statsmodels.api as sm\n\n# 创建数据\ndata = '/home/mw/input/soybean_zhibiao3569/确定指标.csv'\ndf = pd.read_csv(data, encoding='gbk')\nprint(df)\nprint(\"---------------------------------------------\")\ndef vif(df, col_i):\n X = df.drop(col_i, axis=1) # 保留除了当前列之外的所有列\n y = df[col_i] # 当前列作为响应变量\n X = sm.add_constant(X) # 添加截距项\n\n try:\n model = sm.OLS(y, X).fit()\n r2 = model.rsquared\n eps = 1e-9 # 用来避免除以零的小正数\n vif_value = 1. / (1. - r2 + eps) # 加上 eps 防止除以零\n return vif_value\n except Exception as e:\n print(f\"Error computing VIF for {col_i}: {e}\")\n return None\n# 选择计算VIF的列\ntest_data = df[[ '成本利润率(%/亩)','每亩用工数量(日)',\n '土地成本(元/亩)','生产成本(元/亩)','人工成本(元/亩)',\n '农业生产指数(上年=100)','大豆进口数量(吨)','产值合计(元/亩)',\n '农村用电量(万千瓦时)','农作物受灾面积(千公顷)','乡村户数(万户)',\n '大豆播种面积(万公顷)','全国农业科技进步贡献率(%)']]\n#'成本利润率(%/亩)','净利润(元/亩)',\n# 循环计算每一列的VIF\nprint(\"方差膨胀因子(VIF):\")\nfor i in test_data.columns:\n print(i, '\\t', vif(df=test_data, col_i=i))\n","outputs":[{"output_type":"stream","name":"stdout","text":" 年份 成本利润率(%/亩) 净利润(元/亩) 每亩化肥用量(公斤) 每亩种子用量(公斤) 农业机械总动力(万千瓦) \\\n0 2007 42.92 122.92 9.11 4.80 2785.3 \n1 2008 43.36 153.63 9.18 4.85 3018.4 \n2 2009 22.10 85.06 10.05 4.79 3401.3 \n3 2010 28.14 122.11 10.35 4.76 3736.3 \n4 2011 20.99 105.81 10.19 4.58 4097.8 \n5 2012 14.35 84.06 10.80 4.61 4549.3 \n6 2013 -4.00 -25.31 10.76 4.90 4848.7 \n7 2014 4.76 30.98 10.44 5.04 5155.5 \n8 2015 -20.63 -137.71 10.08 5.11 5442.7 \n9 2016 -38.78 -259.97 10.22 5.17 5634.3 \n10 2017 -19.86 -130.52 10.32 5.06 5813.8 \n11 2018 -29.28 -198.30 10.31 5.03 6082.4 \n12 2019 -36.31 -263.55 10.35 4.98 5273.5 \n13 2020 -17.61 -137.92 10.66 5.30 6775.1 \n14 2021 -4.05 -34.96 10.49 5.07 6888.4 \n\n 每亩用工数量(日) 土地成本(元/亩) 生产成本(元/亩) 人工成本(元/亩) 农业生产指数(上年=100) 大豆进口数量(吨) \\\n0 2.94 100.19 186.20 59.72 103.3 237947 \n1 2.51 126.23 228.11 60.42 112.7 424775 \n2 2.87 148.17 236.64 80.18 105.1 1884776 \n3 2.23 174.65 259.28 83.58 108.9 2502408 \n4 2.12 207.70 296.35 101.19 110.0 1967345 \n5 2.03 238.16 129.21 129.21 107.5 2081095 \n6 1.89 272.56 360.08 139.29 107.5 2907805 \n7 1.76 295.18 355.02 139.74 107.7 3458842 \n8 1.67 312.67 354.92 140.39 107.3 3326583 \n9 1.65 313.10 357.35 146.39 105.4 2992664 \n10 1.70 294.08 363.17 152.47 104.1 1939894 \n11 1.70 305.09 372.06 158.61 104.5 1602347 \n12 1.85 351.82 374.01 175.34 102.5 2297826 \n13 1.92 365.82 417.59 193.36 101.4 2067451 \n14 1.73 461.04 403.25 172.37 105.8 2665365 \n\n 产值合计(元/亩) 大豆单位面积产量(千克/公顷) 农村用电量(万千瓦时) 农作物受灾面积(千公顷) 乡村户数(万户) \\\n0 409.31 1138 410335 6653.0 493.9 \n1 507.97 1508 442525 2367.0 504.9 \n2 469.87 1470 484379 7394.0 509.5 \n3 556.04 1651 557278 1432.2 509.1 \n4 609.86 1759 701381 1536.8 512.5 \n5 669.68 1823 643269 2429.4 514.1 \n6 607.33 1722 669533 2734.1 517.7 \n7 681.18 1840 695625 810.0 520.5 \n8 529.88 1874 725812 1175.3 524.5 \n9 410.48 1746 774675 4223.7 521.3 \n10 526.73 1846 797667 1550.5 523.5 \n11 478.85 1844 828042 4155.0 530.8 \n12 462.28 1824 856368 3540.7 545.1 \n13 645.49 1905 897225 3178.5 545.5 \n14 829.33 1849 939945 831.5 518.2 \n\n 大豆播种面积(万公顷) 全国农业科技进步贡献率(%) \n0 397.9 48.0 \n1 414.8 49.0 \n2 416.5 51.0 \n3 372.7 52.0 \n4 340.2 53.5 \n5 286.0 54.5 \n6 263.7 55.2 \n7 279.3 55.6 \n8 266.1 56.1 \n9 322.3 56.7 \n10 373.5 57.5 \n11 356.8 58.3 \n12 427.9 59.2 \n13 483.2 60.7 \n14 388.8 61.5 \n---------------------------------------------\n方差膨胀因子(VIF):\n成本利润率(%/亩) \t 629.1342037882132\n每亩用工数量(日) \t 184.95778284128573\n土地成本(元/亩) \t 61.956941091714825\n生产成本(元/亩) \t 4.450716858203173\n人工成本(元/亩) \t 703.5699882225157\n农业生产指数(上年=100) \t 52.35976355477664\n大豆进口数量(吨) \t 19.232622041489947\n产值合计(元/亩) \t 388.5374748023565\n农村用电量(万千瓦时) \t 75.33610480519572\n农作物受灾面积(千公顷) \t 26.16095026219528\n乡村户数(万户) \t 86.87048268429862\n大豆播种面积(万公顷) \t 20.850065579938875\n全国农业科技进步贡献率(%) \t 891.3790734508566\n"}],"execution_count":19},{"cell_type":"markdown","metadata":{"id":"1D4C0A8E1371477E9A6E264835493D12","notebookId":"661cf2e1d60ce3fe5bf37cc2","runtime":{"status":"default","execution_status":null,"is_visible":false},"jupyter":{},"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"}},"source":"Pearson相关系数"},{"cell_type":"code","metadata":{"id":"A673548E181540A1A17A1ABBD0A414C7","notebookId":"661cf2e1d60ce3fe5bf37cc2","jupyter":{},"collapsed":false,"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"},"trusted":true},"source":"import pandas as pd\nfrom scipy.stats import pearsonr\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport numpy as np\ndf = pd.read_csv('/home/mw/input/soybean_zhibiao3569/Pearson检验指标筛选.csv',encoding='gbk')\n#计算相关系数\ncorr_matrix=df.corr()\n#使用seaborn绘制热图\nplt.rcParams['font.sans-serif']=['Source Han Sans CN']#使用黑体\nplt.rcParams['axes.unicode_minus']=False#正确显示负号\nplt.figure(figsize=(10,8))\nsns.heatmap(corr_matrix,annot=True,cmap='coolwarm',linewidths=5,\n xticklabels=corr_matrix.columns,yticklabels=corr_matrix.columns)\nplt.show()\n#进行显著性检验\np_value,t_value=pearsonr(df['大豆单位面积产量(千克/公顷)'],df['全国农业科技进步贡献率(%)'])\n'''\n'成本利润率(%/亩)','每亩用工数量(日)',\n'土地成本(元/亩)','生产成本(元/亩)','人工成本(元/亩)',\n'农业生产指数(上年=100)','大豆进口数量(吨)','产值合计(元/亩)',\n'农村用电量(万千瓦时)','农作物受灾面积(千公顷)','乡村户数(万户)',\n'大豆播种面积(万公顷)','全国农业科技进步贡献率(%)'\n'''\nprint(\"相关性系数:\")\nprint(corr_matrix)\nprint(\"p_value:\")\nprint(p_value)\n","outputs":[{"output_type":"display_data","data":{"text/plain":"
","text/html":""},"metadata":{"needs_background":"light"}},{"output_type":"stream","name":"stdout","text":"相关性系数:\n 年份 成本利润率(%/亩) 每亩用工数量(日) 土地成本(元/亩) 生产成本(元/亩) \\\n年份 1.000000 -0.852068 -0.806658 0.963314 0.829561 \n成本利润率(%/亩) -0.852068 1.000000 0.817065 -0.792587 -0.762268 \n每亩用工数量(日) -0.806658 0.817065 1.000000 -0.835707 -0.722365 \n土地成本(元/亩) 0.963314 -0.792587 -0.835707 1.000000 0.807082 \n生产成本(元/亩) 0.829561 -0.762268 -0.722365 0.807082 1.000000 \n人工成本(元/亩) 0.964849 -0.870746 -0.833583 0.942343 0.786001 \n农业生产指数(上年=100) -0.550036 0.548587 0.130469 -0.419942 -0.385583 \n大豆进口数量(吨) 0.476247 -0.558023 -0.704491 0.616927 0.531947 \n产值合计(元/亩) 0.357210 0.058721 -0.351365 0.510998 0.216717 \n大豆单位面积产量(千克/公顷) 0.787287 -0.716495 -0.904797 0.806224 0.642656 \n农村用电量(万千瓦时) 0.975951 -0.833736 -0.847817 0.956013 0.817839 \n农作物受灾面积(千公顷) -0.336693 0.137600 0.648621 -0.448283 -0.336498 \n乡村户数(万户) 0.848371 -0.835799 -0.682511 0.755417 0.737749 \n大豆播种面积(万公顷) 0.125138 0.103495 0.395399 -0.040861 0.076896 \n全国农业科技进步贡献率(%) 0.987630 -0.834971 -0.831122 0.973398 0.810043 \n\n 人工成本(元/亩) 农业生产指数(上年=100) 大豆进口数量(吨) 产值合计(元/亩) \\\n年份 0.964849 -0.550036 0.476247 0.357210 \n成本利润率(%/亩) -0.870746 0.548587 -0.558023 0.058721 \n每亩用工数量(日) -0.833583 0.130469 -0.704491 -0.351365 \n土地成本(元/亩) 0.942343 -0.419942 0.616927 0.510998 \n生产成本(元/亩) 0.786001 -0.385583 0.531947 0.216717 \n人工成本(元/亩) 1.000000 -0.558842 0.560695 0.375390 \n农业生产指数(上年=100) -0.558842 1.000000 -0.016344 0.186941 \n大豆进口数量(吨) 0.560695 -0.016344 1.000000 0.394535 \n产值合计(元/亩) 0.375390 0.186941 0.394535 1.000000 \n大豆单位面积产量(千克/公顷) 0.833631 -0.091296 0.692151 0.503067 \n农村用电量(万千瓦时) 0.955450 -0.462958 0.528193 0.415980 \n农作物受灾面积(千公顷) -0.334374 -0.448195 -0.498229 -0.656521 \n乡村户数(万户) 0.887748 -0.544813 0.427519 0.114990 \n大豆播种面积(万公顷) -0.005707 -0.417430 -0.561356 -0.162632 \n全国农业科技进步贡献率(%) 0.977776 -0.501436 0.557263 0.445832 \n\n 大豆单位面积产量(千克/公顷) 农村用电量(万千瓦时) 农作物受灾面积(千公顷) 乡村户数(万户) \\\n年份 0.787287 0.975951 -0.336693 0.848371 \n成本利润率(%/亩) -0.716495 -0.833736 0.137600 -0.835799 \n每亩用工数量(日) -0.904797 -0.847817 0.648621 -0.682511 \n土地成本(元/亩) 0.806224 0.956013 -0.448283 0.755417 \n生产成本(元/亩) 0.642656 0.817839 -0.336498 0.737749 \n人工成本(元/亩) 0.833631 0.955450 -0.334374 0.887748 \n农业生产指数(上年=100) -0.091296 -0.462958 -0.448195 -0.544813 \n大豆进口数量(吨) 0.692151 0.528193 -0.498229 0.427519 \n产值合计(元/亩) 0.503067 0.415980 -0.656521 0.114990 \n大豆单位面积产量(千克/公顷) 1.000000 0.844645 -0.665045 0.766875 \n农村用电量(万千瓦时) 0.844645 1.000000 -0.420581 0.826156 \n农作物受灾面积(千公顷) -0.665045 -0.420581 1.000000 -0.203781 \n乡村户数(万户) 0.766875 0.826156 -0.203781 1.000000 \n大豆播种面积(万公顷) -0.250507 0.038686 0.381822 0.200642 \n全国农业科技进步贡献率(%) 0.844643 0.986782 -0.389737 0.844880 \n\n 大豆播种面积(万公顷) 全国农业科技进步贡献率(%) \n年份 0.125138 0.987630 \n成本利润率(%/亩) 0.103495 -0.834971 \n每亩用工数量(日) 0.395399 -0.831122 \n土地成本(元/亩) -0.040861 0.973398 \n生产成本(元/亩) 0.076896 0.810043 \n人工成本(元/亩) -0.005707 0.977776 \n农业生产指数(上年=100) -0.417430 -0.501436 \n大豆进口数量(吨) -0.561356 0.557263 \n产值合计(元/亩) -0.162632 0.445832 \n大豆单位面积产量(千克/公顷) -0.250507 0.844643 \n农村用电量(万千瓦时) 0.038686 0.986782 \n农作物受灾面积(千公顷) 0.381822 -0.389737 \n乡村户数(万户) 0.200642 0.844880 \n大豆播种面积(万公顷) 1.000000 0.047069 \n全国农业科技进步贡献率(%) 0.047069 1.000000 \np_value:\n0.8446433829739916\n"}],"execution_count":21},{"cell_type":"markdown","metadata":{"id":"8993025F34184245855F00B398CAD2A8","notebookId":"661cf2e1d60ce3fe5bf37cc2","runtime":{"status":"default","execution_status":null,"is_visible":false},"jupyter":{},"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"}},"source":"## 因子分析"},{"cell_type":"markdown","metadata":{"id":"897996A9126742CBB7C2BCC256806608","notebookId":"661cf2e1d60ce3fe5bf37cc2","runtime":{"status":"default","execution_status":null,"is_visible":false},"jupyter":{},"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"}},"source":"1、KMO检验,如果检验值低于0.5,证明不通过,则前面所处理的各个变量之间的相关性弱,共线性低"},{"cell_type":"code","metadata":{"id":"14E976F3B252434AA86C7AFCC717F01C","notebookId":"661cf2e1d60ce3fe5bf37cc2","jupyter":{},"collapsed":false,"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"},"trusted":true},"source":"# 数据处理\nfrom factor_analyzer.factor_analyzer import calculate_kmo\nimport pandas as pd\ndf = pd.read_csv('/home/mw/input/soybean_zhibiao3569/KMO检验指标.csv',encoding='gbk')\ndf.isnull().sum()\n\n'''\nKMO检验\n检查变量间的相关性和偏相关性,取值在0-1之间;KOM统计量越接近1,\n变量间的相关性越强,偏相关性越弱,因子分析的效果越好。\n通常取值从0.6开始进行因子分析\n'''\n#KMO检验\nkmo_all,kmo_model=calculate_kmo(df)\nprint(\"KMO检验为\",kmo_model)","outputs":[{"output_type":"stream","name":"stdout","text":"KMO检验为 0.7178545041204661\n"}],"execution_count":1},{"cell_type":"markdown","metadata":{"id":"1FB1CD9FF518496E8DB2BEC654823686","notebookId":"661cf2e1d60ce3fe5bf37cc2","runtime":{"status":"default","execution_status":null,"is_visible":false},"jupyter":{},"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"}},"source":"## elastic-net"},{"cell_type":"code","metadata":{"id":"568DC38341FF48589FCE153CCA6A8683","notebookId":"661cf2e1d60ce3fe5bf37cc2","jupyter":{},"collapsed":false,"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"},"trusted":true},"source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport sklearn\nfrom sklearn.linear_model import ElasticNet, Lasso\n\ndf = pd.read_csv(r\"/home/mw/input/soybean_zhibiao3569/确定指标.csv\",encoding=\"gbk\")\nX=df.drop(columns=['大豆单位面积产量(千克/公顷)']) # 特征 \ny = df['大豆单位面积产量(千克/公顷)'] # 目标变量","outputs":[],"execution_count":9},{"cell_type":"markdown","metadata":{"id":"4E5CFF3479694940A518229B156DE0F8","notebookId":"661cf2e1d60ce3fe5bf37cc2","runtime":{"status":"default","execution_status":null,"is_visible":false},"jupyter":{},"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"}},"source":"1、使用scikit-learn拟合"},{"cell_type":"code","metadata":{"id":"E550263E9C0B463F9E2F768B8D25FF63","notebookId":"661cf2e1d60ce3fe5bf37cc2","jupyter":{},"collapsed":false,"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"},"trusted":true},"source":"from sklearn.linear_model import ElasticNet\n\n# 初始化弹性网络回归器\nreg = ElasticNet(alpha=0.1, l1_ratio=0.5, fit_intercept=False)\n# 拟合线性模型\nreg.fit(X, y)\n# 权重系数\nW = reg.coef_\nW\n# 打印特征名称和对应的权重系数\nfeature_names = X.columns\nfor feature, weight in zip(feature_names, W):\n print(f\"Feature: {feature}, Weight: {weight}\")","outputs":[{"output_type":"stream","name":"stdout","text":"Feature: 成本利润率(%/亩), Weight: -13.291612273812861\nFeature: 净利润(元/亩), Weight: 2.1662114169369167\nFeature: 每亩化肥用量(公斤), Weight: 67.01421027055781\nFeature: 每亩种子用量(公斤), Weight: 62.465120332938184\nFeature: 每亩用工数量(日), Weight: -60.52180833428132\nFeature: 人工成本(元/亩), Weight: 2.720548383439563\nFeature: 农业生产指数(上年=100), Weight: 12.003098410978328\nFeature: 乡村户数(万户), Weight: -0.9307138927327461\nFeature: 大豆播种面积(万公顷), Weight: 0.4440202568522585\nFeature: 全国农业科技进步贡献率(%), Weight: -6.816170498790709\n"},{"output_type":"stream","name":"stderr","text":"/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 31210.104818029715, tolerance: 4496.7349\n positive)\n"}],"execution_count":3},{"cell_type":"markdown","metadata":{"id":"D28097BE0FBD4FAEB91F21B58B7DDFFC","notebookId":"661cf2e1d60ce3fe5bf37cc2","runtime":{"status":"default","execution_status":null,"is_visible":false},"jupyter":{},"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"}},"source":"*可视化*"},{"cell_type":"code","metadata":{"id":"22D8777CEE1F4A64B5F2637A323676FF","notebookId":"661cf2e1d60ce3fe5bf37cc2","jupyter":{},"collapsed":false,"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"},"trusted":true},"source":"plt.rcParams['font.sans-serif']=['Source Han Sans CN']\n# 设置正常显示符号\nplt.rcParams[\"axes.unicode_minus\"] = False\n# 可视化特征重要性(条形图展示权重大小)\nfig, ax = plt.subplots(figsize=(14, 8)) # 增大图表尺寸\nindex = np.arange(len(feature_names)) # 特征索引\nbar_width = 0.35 # 设定条形图的宽度\n\n# 绘制条形图\nrects = ax.bar(index, W, bar_width, color='#457b9d', label='权重系数')\n\n# 设置x轴标签\nax.set_xticks(index)\nax.set_xticklabels(feature_names, rotation=45, ha='right') # 旋转x轴标签角度并设置对齐方式\n\n# 设置图表标题和坐标轴标签\nax.set_title('ElasticNet 特征重要性', color='#264653')\nax.set_xlabel('特征', color='#264653')\nax.set_ylabel('权重系数', color='#264653')\n\n# 调整坐标轴刻度标签颜色\nax.tick_params(axis='both', labelcolor='#264653')\n\n# 显示图例\nax.legend()\n\n# 显示图表\nplt.show()\n","outputs":[{"output_type":"display_data","data":{"text/plain":"
","text/html":""},"metadata":{"needs_background":"light"}}],"execution_count":13},{"cell_type":"markdown","metadata":{"id":"5DB12708252B4BB6B7513464709E2C8C","notebookId":"661cf2e1d60ce3fe5bf37cc2","runtime":{"status":"default","execution_status":null,"is_visible":false},"jupyter":{},"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"}},"source":"*计算权重系数*"},{"cell_type":"markdown","metadata":{"id":"90F6A23BCF6847168C652A6B6784FFB3","notebookId":"661cf2e1d60ce3fe5bf37cc2","runtime":{"status":"default","execution_status":null,"is_visible":false},"jupyter":{},"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"}},"source":"*P对弹性网络回归的影响*"},{"cell_type":"code","metadata":{"id":"B1BE3FCC2CC842FEAF62C05E6DE4B720","notebookId":"661cf2e1d60ce3fe5bf37cc2","jupyter":{},"collapsed":false,"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"},"trusted":true},"source":"import pandas as pd \nimport numpy as np \nimport matplotlib.pyplot as plt \nfrom sklearn.linear_model import ElasticNet \nplt.rcParams['font.sans-serif']=['Source Han Sans CN']\n# 设置正常显示符号\nplt.rcParams[\"axes.unicode_minus\"] = False\n# 加载数据 \ndf = pd.read_excel(\"/home/mw/input/soybean_zhibiao3569/Elastic-net检验.xls\", encoding=\"gbk\") \nX = df.drop(columns=['大豆单位面积产量(千克/公顷)','年份']) # 特征 \ny = df['大豆单位面积产量(千克/公顷)'] # 目标变量 \n \n# 定义alpha值的范围 \nalphas = np.logspace(-4, 2, 10) # 从0.0001到100的等比数列 \n \n# 初始化用于存储系数的数组 \ncoefs = np.zeros((len(alphas), X.shape[1])) \n \n# 拟合不同alpha值的模型,并存储系数 \nfor i, alpha in enumerate(alphas): \n reg = ElasticNet(alpha=alpha, l1_ratio=0.5, fit_intercept=False) \n reg.fit(X, y) \n coefs[i] = reg.coef_ \n \n# 绘制系数随alpha的变化 \nplt.figure(figsize=(10, 6)) \nfor i, feature in enumerate(X.columns): \n plt.plot(alphas, coefs[:, i], label=feature) \n \nplt.xscale('log') \nplt.xlabel('alpha') \nplt.ylabel('系数') \nplt.title('随着alpha 变化的弹性网络系数') \nplt.legend() \nplt.grid(True) \nplt.show()","outputs":[{"output_type":"stream","name":"stderr","text":"/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17937.272764048856, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18128.852212569585, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18981.626559065342, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 22271.992394899866, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 29560.935872549482, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 27843.82244455605, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 23327.06423298886, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 31719.470326737035, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 22141.177524485727, tolerance: 4496.7349\n positive)\n"},{"output_type":"display_data","data":{"text/plain":"
","text/html":""},"metadata":{"needs_background":"light"}}],"execution_count":5},{"cell_type":"markdown","metadata":{"id":"2D2F2EA2F4A5436D83671C2A4B01490D","notebookId":"661cf2e1d60ce3fe5bf37cc2","runtime":{"status":"default","execution_status":null,"is_visible":false},"jupyter":{},"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"}},"source":"*弹性网络回归与Lasso对比*"},{"cell_type":"code","metadata":{"id":"288BBBED11F64549873BE80B932E1B3F","notebookId":"661cf2e1d60ce3fe5bf37cc2","jupyter":{},"collapsed":false,"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"},"trusted":true},"source":"import numpy as np \nimport matplotlib.pyplot as plt \nimport pandas as pd \nfrom sklearn.linear_model import ElasticNet, Lasso \nimport matplotlib.pyplot as plt\nplt.rcParams['font.sans-serif']=['Source Han Sans CN']\n# 设置正常显示符号\nplt.rcParams[\"axes.unicode_minus\"] = False\n# 加载大豆数据 \ndf = pd.read_excel(r\"/home/mw/input/soybean_zhibiao3569/Elastic-net检验.xls\", encoding=\"gbk\") \nX = df.drop(columns=['大豆单位面积产量(千克/公顷)','年份']) # 特征 \ny = df['大豆单位面积产量(千克/公顷)'] # 目标变量 \n \n# 定义正则化强度的范围 \nn_alphas = 100 \nalphas = np.logspace(-3, 0.5, n_alphas) \n \n# 初始化ElasticNet和Lasso模型,并收集系数 \ncoefs_enet = [] \ncoefs_lasso = [] \n \nfor a in alphas: \n # ElasticNet \n reg_enet = ElasticNet(alpha=a, l1_ratio=0.9, fit_intercept=False) \n reg_enet.fit(X, y) \n coefs_enet.append(reg_enet.coef_) \n \n # Lasso \n reg_lasso = Lasso(alpha=a, fit_intercept=False) \n reg_lasso.fit(X, y) \n coefs_lasso.append(reg_lasso.coef_) \n \n# 准备绘制图像 \nplt.figure(figsize=(14, 7)) \n \n# 绘制ElasticNet系数随alpha变化的图像 \nplt.subplot(1, 2, 1) \nfor i, coef in enumerate(coefs_enet[0]): # 只取第一个alpha值对应的系数进行展示 \n plt.plot(alphas, [c[i] for c in coefs_enet], label=X.columns[i]) \nplt.xlabel('alpha') \nplt.ylabel('系数') \nplt.title('Elastic-Net系数') \nplt.xscale('log') \nplt.legend(loc='best', ncol=2) # 调整图例位置,避免重叠 \n \n# 绘制Lasso系数随alpha变化的图像 \nplt.subplot(1, 2, 2) \nfor i, coef in enumerate(coefs_lasso[0]): # 只取第一个alpha值对应的系数进行展示 \n plt.plot(alphas, [c[i] for c in coefs_lasso], label=X.columns[i], linestyle='--') \nplt.xlabel('alpha') \nplt.ylabel('系数') \nplt.title('Lasso 系数') \nplt.xscale('log') \nplt.legend(loc='best', ncol=2) # 调整图例位置,避免重叠 \n \n# 突出显示重要特征(例如,基于系数绝对值的大小) \n# 这里您可以根据需要添加逻辑来突出显示特征 \n \n# 调整子图之间的间距并显示图像 \nplt.tight_layout() \nplt.show()","outputs":[{"output_type":"stream","name":"stderr","text":"/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17996.419092196647, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17892.005491248765, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18005.89712863896, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17892.670957592014, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18016.171460924463, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17893.39284892134, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18027.30829937717, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17894.175948326556, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18039.379238022324, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17895.0254441418, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18052.461670880108, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17895.946964247116, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18066.639237484844, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17896.946613257616, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18082.002293787034, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17898.03101285933, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18098.648421073547, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17899.207345538627, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18116.682963227642, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17900.483402017137, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18136.21959121918, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17901.867632660862, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18157.380909130614, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17903.369203244893, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18180.29908912318, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17904.998055399188, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18205.113009289256, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17906.764972139445, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18231.982770453353, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17908.68164892032, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18261.07014720554, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17910.76077065305, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18292.55259592623, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17913.016095193496, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18326.62079590746, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17915.46254381882, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18363.47947149998, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17918.116299320372, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18403.348225228234, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17920.994912279915, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18446.462373845763, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17924.117416244084, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18493.073805928252, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17927.50445253473, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18543.45182161701, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17931.178405450933, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18597.883960594263, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17935.16354875313, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18656.667794346384, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17939.48620431942, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18720.14687606078, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17944.174913988205, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18788.659741235453, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17949.260625642684, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18862.574217843805, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17954.77689468126, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18942.27962356894, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17960.760102133994, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 19028.187050566783, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17967.24969072097, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 19120.714182994026, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17974.288410776004, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 19220.344878703265, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17981.922633757873, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 19327.54288319128, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17990.202596928055, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 19442.80139378178, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 17999.182761905795, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 19566.615948273735, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18008.922155531036, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 19699.561870211073, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18019.48474754045, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 19842.168116624143, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18030.91482277421, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 19994.967396878244, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18043.335413718323, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 20158.585364798553, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18056.804828145196, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 20333.57094479649, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18071.41120950573, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 20520.4605209049, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18087.250033930588, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 20719.898751033055, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18104.424674418453, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 20932.35026471692, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18123.04716922874, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 21158.437944412093, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18143.23873108857, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 21398.56051340712, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18165.130610113873, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 21653.247839463565, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18188.86486535624, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 21922.880695507694, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18214.595224456752, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 22207.733817300188, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18242.4255627186, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 22508.085283273223, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18272.65519707042, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 22824.173863487835, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18305.421195248, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 23155.82785156543, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18340.933817418332, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 23503.017079672183, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18379.42018114715, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 23865.473530535935, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18421.12602237802, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 24242.713795569907, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18466.212774441512, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 24634.101227215106, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18515.164357817725, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 25038.720854311476, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18568.19475874159, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 25455.47430026652, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18625.63685258571, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 25882.926070772297, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18687.703325964074, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 26319.21419741661, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18755.060086805348, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 26762.7365559604, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18827.988908234507, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 27210.977682810088, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18906.748207552297, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 27661.00171802115, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 18992.181491167776, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 28110.32463251364, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 19084.58931774467, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 28554.993087133873, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 19184.404448853264, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 28991.89825552664, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 19292.568021660336, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 29416.29771043779, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 19409.23476755608, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 29824.387679225165, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 19535.64862485808, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 30210.724108503815, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 19671.90951267524, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 30570.569561595432, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 19819.077328243315, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 30898.63627610486, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 19978.38967447237, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 31189.975078594875, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 20149.896172360233, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 31438.1237905924, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 20334.89877761723, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 31638.239126788423, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 20534.514693189965, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 31785.071478369082, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 20749.890663764032, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 31873.946548390144, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 20981.376153211022, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 31900.67551108121, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 21230.54953416367, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 31861.929006678984, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 21498.414815799704, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 31755.89323888891, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 21786.206762121466, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 31581.306274360868, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 22095.119207537085, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 31338.60916417832, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 22425.828076841484, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 31030.113120337024, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 22779.852320710837, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 30659.853542361943, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 23159.188367370716, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 30237.190522200755, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 23564.50723293644, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 29766.580864046075, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 23995.063214002632, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 29255.811118909627, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 24454.513464606105, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 28714.85521813831, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 24941.58517251286, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 28154.192484101433, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 25457.92297575256, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 27583.90055330376, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 26002.412535070383, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 27015.642901375923, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 26577.232690114764, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 26459.6109378636, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 27177.62288063425, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 25926.18456535915, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 27806.32918704961, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 25424.382409231966, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 28459.976047665237, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 24962.541972388633, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 29133.241841122206, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 24547.45482823044, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 29822.461689002725, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 24181.63612993749, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 30523.717351706146, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 23876.476618368186, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 31227.329610704248, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 23653.902229815347, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 31923.33652061757, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 23609.873449461757, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 32597.503050678402, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 23593.373036492845, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 33232.40553775738, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 23596.099954824378, tolerance: 4496.7349\n positive)\n/opt/conda/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:475: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 33805.61669473829, tolerance: 4496.7349\n positive)\n"},{"output_type":"display_data","data":{"text/plain":"
","text/html":""},"metadata":{"needs_background":"light"}}],"execution_count":9},{"cell_type":"markdown","metadata":{"id":"8945683D818549C3ADBA3059301758C8","notebookId":"661cf2e1d60ce3fe5bf37cc2","runtime":{"status":"default","execution_status":null,"is_visible":false},"jupyter":{},"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"}},"source":"## R²检验"},{"cell_type":"code","metadata":{"id":"945D49C6D18F4875873F5E8CA390ADF9","notebookId":"661cf2e1d60ce3fe5bf37cc2","jupyter":{},"collapsed":false,"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"},"trusted":true},"source":"'''\n对多模型权重系数检验\n'''\nimport statsmodels.api as sm\nimport pandas as pd\n\n# 读取数据\ndata = pd.read_csv(r\"/home/mw/input/soybean_zhibiao3569/多模型筛选后.csv\",encoding='gbk')\n\n# 拟合回归模型\nx = data.drop(columns=['大豆单位面积产量(千克/公顷)','年份']) # 特征 \ny = data['大豆单位面积产量(千克/公顷)']\n\nX = sm.add_constant(x)\nmodel = sm.OLS(y, X).fit() # 注意这里使用X而不是x,并且fit()方法调用没有空格\n\n# 显示调整后的R平方\nprint(\"经过OLS模型、VIF、Pearson相关系数处理,进行R²检验的值:\")\nprint(model.rsquared_adj) # 注意没有空格,并且前面有model.前缀\n","outputs":[{"output_type":"stream","name":"stdout","text":"经过OLS模型、VIF、Pearson相关系数处理,进行R²检验的值:\n0.8916363808155049\n"}],"execution_count":25},{"cell_type":"code","metadata":{"id":"8ADDEA6DF38B460E95A584818D755F9B","notebookId":"661cf2e1d60ce3fe5bf37cc2","jupyter":{},"collapsed":false,"scrolled":false,"tags":[],"slideshow":{"slide_type":"slide"},"trusted":true},"source":"'''\nElastic-Net权重系数检验\n'''\nimport statsmodels.api as sm\nimport pandas as pd\n\n# 读取数据\ndata = pd.read_excel(\"/home/mw/input/soybean_zhibiao3569/Elastic-net检验.xls\",encoding='gbk')\n\n# 拟合回归模型\nx = data.drop(columns=['大豆单位面积产量(千克/公顷)','年份']) # 特征 \ny = data['大豆单位面积产量(千克/公顷)']\n\nX = sm.add_constant(x)\nmodel = sm.OLS(y, X).fit() # 注意这里使用X而不是x,并且fit()方法调用没有空格\n\n# 显示调整后的R平方\nprint(\"经过Elastic-Net回归算法处理,进行R²检验的值:\")\nprint(model.rsquared_adj) # 注意没有空格,并且前面有model.前缀","outputs":[{"output_type":"stream","name":"stdout","text":"经过Elastic-Net回归算法处理,进行R²检验的值:\n0.9458706826994898\n"}],"execution_count":22}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python","nbconvert_exporter":"python","file_extension":".py","version":"3.5.2","pygments_lexer":"ipython3"}},"nbformat":4,"nbformat_minor":0} 2 | --------------------------------------------------------------------------------