【问题标题】:How to use IP address converted to integer in machine learning model如何在机器学习模型中使用转换为整数的 IP 地址
【发布时间】:2020-03-09 14:43:28
【问题描述】:

我有一个将IP地址转换为整数值的函数:

def convertIpToInt(ip):
    return sum([int(ipField) << 8*index for index, ipField in enumerate(reversed(ip.split('.')))])

convertIpToInt('149.170.10.1') -> 2510948865

它工作正常并给出一个整数值,但如何在分类模型中使用这些值? 我应该缩放这些值,还是有什么其他选项可以处理此类数据?

【问题讨论】:

标签: pandas dataframe machine-learning classification


【解决方案1】:

您必须将 IP 转换为机器学习算法的标识符,为此您可以使用标签编码器。这会将您的 IP 转换为数字。

from sklearn import preprocessing le = preprocessing.LabelEncoder() le.fit(["ip1", "ip2", "ip3", "ip4"]) le.transform(["ip1", "ip2", "ip1"])

链接:https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.LabelEncoder.html

如果您认为这可以增加某些 IP(功能)的权重,那么您可以使用 One Hot 编码。

链接:https://machinelearningmastery.com/why-one-hot-encode-data-in-machine-learning/

【讨论】:

    猜你喜欢
    • 2019-11-03
    • 1970-01-01
    • 2020-03-20
    • 2020-08-16
    • 1970-01-01
    • 1970-01-01
    • 2019-11-15
    • 1970-01-01
    • 2016-08-16
    相关资源
    最近更新 更多