机器学习日志_20211022

from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer
import jieba
from sklearn.preprocessing import StandardScaler
from sklearn.impute import SimpleImputer
import numpy as np


def cut_word():
    sentence1 = "今天很残酷,明天更残酷,后天很美好,但绝对大部分是死在明天晚上,所以每个人不要放弃今天。"
    sentence2 = "我们看到的从很远星系来的光是在几百万年之前发出的,这样当我们看到宇宙时,我们是在看它的过去。"
    sentence3 = "如果只用一种方式了解某样事物,你就不会真正了解它。了解事物真正含义的秘密取决于如何将其与我们所了解的事物相联系。"
    c1 = jieba.cut(sentence1)
    c2 = jieba.cut(sentence2)
    c3 = jieba.cut(sentence3)

    c1 = ' '.join(list(c1))
    c2 = ' '.join(list(c2))
    c3 = ' '.join(list(c3))
    return c1, c2, c3


def my_count():
    c1, c2, c3 = cut_word()
    count = CountVectorizer()
    data = count.fit_transform([c1, c2, c3])
    print(count.get_feature_names())
    print(data)
    print(data.toarray())


def my_count2():
    c1, c2, c3 = cut_word()
    tf = TfidfVectorizer()
    data = tf.fit_transform([c1, c2, c3])
    print(tf.get_feature_names())
    print(data)
    print(data.toarray())


def stand():
    """
    标准化处理
    :return:
    """
    standard = StandardScaler()
    data = standard.fit_transform([[1., -1., 3.], [2., 4., 2.], [4., 6., -1.]])
    print(data)


def im():
    im = SimpleImputer(missing_values=np.nan, strategy='mean')
    data = im.fit_transform([[1, 2], [np.nan, 3], [7, 6]])
    print(data)
    pass


if __name__ == "__main__":
    # my_count2()
    # stand()
    im()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值