簡體   English   中英

機器學習問題(解決 ValueError:無法將字符串轉換為浮點數:)

[英]Machine Learning question (Solving ValueError: could not convert string to float:)

我正在運行下面的示例代碼:

import pandas as pd

from sklearn.tree import DecisionTreeClassifier

from sklearn.preprocessing import OneHotEncoder

CSV 的外觀

url_data = pd.read_csv('phishing_site_urls.csv')

url_data.drop_duplicates(inplace = True)
print(url_data.shape)


#X = input Data (Urls) // Y = output (Wether its Bad or Good)

X = url_data.drop(columns=['Label'])
y = url_data['Label']

model = DecisionTreeClassifier()

model.fit(X, y)
predictions = model.predict([["Paste suspected Phishy Link here"]])

print(predictions)

**-使用名為 phishing_site_urls.csv 的 csv,它有兩列,一列名為“URL”,另一列名為“標簽”。 其中 URL 列包含釣魚鏈接或有效鏈接,並且標簽列具有相應的“壞”或“好”,用於確定 URL 列中的哪個鏈接是釣魚鏈接或有效鏈接。

-我的問題是我不斷收到錯誤消息:“ValueError:無法將字符串轉換為浮點數:”我認為必須有某種方式將鏈接從字符串編碼為浮點數,以便模型可以運行? 如果是這樣,我將不勝感激有關如何做到這一點的一些見解。**

我假設您是機器學習的新手,因此在深入研究神經網絡和 NLP(自然語言處理)論文之前,我認為熟悉如何在不同場景中對分類數據進行編碼將是一個很好的第一步。 您可以在此處查看指南:(第 6.3.4節是用於編碼分類數據的部分)

https://scikit-learn.org/stable/modules/preprocessing.html

我還假設這個數據集只是為了練習,所以在你不熟悉文本預處理/詞嵌入等之前,最好選擇更容易的數據集而不是直接跳到這個數據集。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM