第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

導(dǎo)入 CSV,為邏輯回歸重塑變量數(shù)組

導(dǎo)入 CSV,為邏輯回歸重塑變量數(shù)組

炎炎設(shè)計(jì) 2022-10-06 18:41:43
我希望每個(gè)人都在 COVID-19 大流行中保持安全。我是 Python 新手,有一個(gè)關(guān)于將數(shù)據(jù)從 CSV 導(dǎo)入 Python 以進(jìn)行簡(jiǎn)單邏輯回歸分析的快速問題,其中因變量是二元的,自變量是連續(xù)的。我導(dǎo)入了一個(gè) CSV 文件,然后希望使用一個(gè)變量(Active)作為自變量,另一個(gè)變量(Smoke)作為響應(yīng)變量。我能夠?qū)?CSV 文件加載到 Python 中,但每次我嘗試生成邏輯回歸模型來預(yù)測(cè)來自運(yùn)動(dòng)的煙霧時(shí),我都會(huì)收到一個(gè)錯(cuò)誤,即運(yùn)動(dòng)必須重新整形為一列(二維),因?yàn)樗壳笆且涣芯S度。import matplotlib.pyplot as pltimport numpy as npimport pandas as pdfrom sklearn.linear_model import LogisticRegressionfrom sklearn.metrics import classification_report, confusion_matrixdata = pd.read_csv('Pulse.csv') # Read the data from the CSV filex = data['Active'] # Load the values from Exercise into the independent variablex = np.array.reshape(-1,1)y = data['Smoke'] # The dependent variable is set as Smoke我不斷收到以下錯(cuò)誤消息:83. 102. 102. 106. 79. 80. 79. 110. 144. 80. 97. 60. 80. 108. 107. 51. 68. 80. 80. 60. 64. 87. 110. 110. 82. 154. 139. 86. 95. 112. 120. 79. 64. 84. 65. 60. 79. 79. 70. 75. 107. 78. 74. 80. 121. 120. 96. 75. 106. 88. 91. 98. 63. 95. 85. 83. 92. 81. 89. 103. 110. 78. 122. 122. 71. 65. 92. 93. 88. 90. 56. 95. 83. 97. 105. 82. 102. 87. 81.]。如果您的數(shù)據(jù)具有單個(gè)特征,則使用 array.reshape(-1, 1) 重塑您的數(shù)據(jù),如果它包含單個(gè)樣本,則使用 array.reshape(1, -1) 。89. 103. 110. 78. 122. 122. 71. 65. 92. 93. 88. 90. 56. 95. 83. 97. 105. 82. 102. 87. 81.]。如果您的數(shù)據(jù)具有單個(gè)特征,則使用 array.reshape(-1, 1) 重塑您的數(shù)據(jù),如果它包含單個(gè)樣本,則使用 array.reshape(1, -1) 。89. 103. 110. 78. 122. 122. 71. 65. 92. 93. 88. 90. 56. 95. 83. 97. 105. 82. 102. 87. 81.]。如果您的數(shù)據(jù)具有單個(gè)特征,則使用 array.reshape(-1, 1) 重塑您的數(shù)據(jù),如果它包含單個(gè)樣本,則使用 array.reshape(1, -1) 。以下是包含錯(cuò)誤的完整更新代碼(2020 年 4 月 12 日): *我無(wú)法將錯(cuò)誤日志輸入到此文檔中,因此我已將其復(fù)制并粘貼到此公共 Google 文檔中:https://docs.google。 com/document/d/1vtrj6Znv54FJ4Zvv211TQvvCN6Ac5LDaOfvHicQn0nU/edit?usp=sharing此外,這里是 CSV 文件: https ://drive.google.com/file/d/1g_-vPNklxRn_3nlNPsR-IOflLfXSzFb1/view?usp=sharing
查看完整描述

2 回答

?
慕沐林林

TA貢獻(xiàn)2016條經(jīng)驗(yàn) 獲得超9個(gè)贊

下面的代碼應(yīng)該可以工作:


import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

from sklearn.linear_model import LogisticRegression

from sklearn.metrics import classification_report, confusion_matrix

data = pd.read_csv('Pulse.csv')

x = pd.DataFrame(data['Smoke'])

y = data['Smoke']

lr = LogisticRegression()

lr.fit(x,y)

p_pred = lr.predict_proba(x)

y_pred = lr.predict(x)

score_ = lr.score(x,y)

conf_m = confusion_matrix(y,y_pred)

report = classification_report(y,y_pred)


print(score_)

0.8836206896551724


print(conf_m)

[[204   2]

 [ 25   1]]


查看完整回答
反對(duì) 回復(fù) 2022-10-06
?
四季花海

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超5個(gè)贊

嘗試這個(gè):


import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

from sklearn.linear_model import LogisticRegression

from sklearn.metrics import classification_report, confusion_matrix


data = pd.read_csv('Pulse.csv') # Read the data from the CSV file

x = data['Active'] # Load the values from Exercise into the independent variable

y = data['Smoke'] # The dependent variable is set as Smoke


lr = LogisticRegression().fit(x.values.reshape(-1,1), y)


查看完整回答
反對(duì) 回復(fù) 2022-10-06
  • 2 回答
  • 0 關(guān)注
  • 143 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)