2016-09-15 36 views
-2

的代碼實際上是從工作 使用通過蟒蛇和Spyder的IDE 最新版本的Python有了Spyder的 code screenshotPython庫但未使用的導入

from pandas import Series, DataFrame 
import pandas as pd 
import numpy as np 
import matplotlib as plt 
import os 
from sklearn.cross_validation import train_test_split 
from sklearn.tree import DecisionTreeClassifier 
import sklearn.metrics 
from sklearn.metrics import classification_report 

代碼分析表明大熊貓庫中導入應用程序重新編寫但未使用。

請大家幫幫忙蟒蛇noobie

感謝您的意見,我學習!

我已經既沒有進口的建議和控制檯返回所看到的SS console error messages

>>> runfile('C:/Users/dbldee/Desktop/TREES/Decisiontree.py', wdir='C:/Users/dbldee/Desktop/TREES') 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "C:\Users\dbldee\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 714, in runfile 
    execfile(filename, namespace) 
    File "C:\Users\dbldee\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 89, in execfile 
    exec(compile(f.read(), filename, 'exec'), namespace) 
    File "C:/Users/dbldee/Desktop/TREES/Decisiontree.py", line 42, in <module> 
    classifier = classifier.fit(pred_train,tar_train) 
TypeError: fit() missing 1 required positional argument: 'y' 
>>> 

這表明該問題可能與該文件的讀取錯誤運行腳本?

+0

您應該能夠刪除這些導入,但應該在之後測試您的代碼,以確保這不會導致任何意外問題。 – Jaco

+0

您能否提供一個示例 - 如果您遇到這些導入問題? – estebanpdl

+0

@flippy,這部分腳本似乎是防止執行<從熊貓進口系列問題的來源,數據幀 進口熊貓作爲PD 進口numpy的作爲NP 進口OS 進口matplotlib.pylab從sklearn.cross_validation PLT 進口train_test_split 從sklearn.tree進口DecisionTreeClassifier 從sklearn.metrics導入classification_report 進口sklearn.metrics os.chdir( 'C:\\用戶\\ dbldee \\桌面\\ TREES') 「」」 數據工程與分析「 AH_data = pd.read_csv(「tree_addhealth.csv」) – dbldee

回答

2

Spyder正在做一個static check來幫助你的Python程序的正確性。您可能可以按照原樣運行,但該工具正在幫助您使用Python風格和簡潔。

嘗試刪除線

import pandas as pd 

,它應該停止抱怨。試着按照IDE的建議打破和改變程序,而不用擔心打破程序,這將使你學習。

+1

我真的認爲人們現在依賴IDE /文本編輯器。 +1告訴他不要害怕違背IDE的建議,只看到會發生什麼。你應該知道你爲什麼做事,而不是盲目地做。 –