天天看點

PyCharm運作報錯:TypeError: fit() got an unexpected keyword argument ‘n_components‘

事情是這樣的,由于個人懶惰的原因,故我調用了一個sklearn的包實作PCA降維

# sklearn實作PCA降維
def Sklearn_Pca(dataset):
    """
    對原始資料進行降維處理,并儲存為降維後的資料表
    :param dataset: 原始資料表,單一層
    :return: 傳回pca後的降維資料
    """
    pca = PCA(n_components=4, copy=True, whiten=False)   # ‘mle’方法自動選取次元,保留幾次元資料
    # pca.fit(dataset)
    pca_result = pca.fit_transform(dataset)    # 輸出降維後的資料
    # print(pca_result)

    return pca_result      

然後,

就給我爆出個這

PyCharm運作報錯:TypeError: fit() got an unexpected keyword argument ‘n_components‘

然後我就蚌湖住了

發現C站沒有相關解答,害!~

然後就看看看看,找到了sklearn的原始封包檔,發現

“我是廢物!!!”

并沒有下面這個用法(盆友們一點要細心呀!~)

PyCharm運作報錯:TypeError: fit() got an unexpected keyword argument ‘n_components‘

修改為下即可

PyCharm運作報錯:TypeError: fit() got an unexpected keyword argument ‘n_components‘

就能正常運作了。