(MOOC)机器学习之人体运动状态预测可运行代码(2022.7.15)

具体代码注释及算法原理可见博客https://andyguo.blog.csdn.net/article/details/104336532https://andyguo.blog.csdn.net/article/details/104336532

以及机器学习应用——监督学习(上)(实例:人体运动状态预测&人体运动状态预测&房价与房屋尺寸关系的线性拟合与非线性拟合&交通流量预测)_柠檬茶@的博客-CSDN博客_监督学习例子前言机器学习应用博客中,将核心介绍三大类学习,即:无监督学习、监督学习、强化学习。本篇将简要介绍:1.监督学习概念(最常应用场景:分类和回归)2.分类——k近邻分类器、决策树、朴素贝叶斯(人体运动状态预测)、SVM(人体运动状态预测)3.回归——线性回归(Linear Regression)(房价与房屋尺寸关系的线性拟合);多项式回归(Polynomial Regression)(房价与房屋尺寸的非线性拟合);岭回归(ridge regression)(交通流量预测)一、监督学习1.监督学习的https://blog.csdn.net/qq_51308373/article/details/122115009?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165763652416780357219429%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=165763652416780357219429&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-4-122115009-null-null.185%5Ev2%5Econtrol&utm_term=python%E4%BA%BA%E4%BD%93%E8%BF%90%E5%8A%A8%E7%8A%B6%E6%80%81%E9%A2%84%E6%B5%8B&spm=1018.2226.3001.4450

 本文仅提供可运行代码及所需数据(是在以上博客的基础上修改了个别错误)

import numpy as np
import pandas as pd

from sklearn.impute import SimpleImputer
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report

from sklearn.neighbors import KNeighborsClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.naive_bayes import GaussianNB

def load_dataset(feature_paths, label_paths):
    feature = np.ndarray(shape=(0,41))
    label = np.ndarray(shape=(0,1))
    for file in feature_paths:
        df = pd.read_table(file, delimiter=',', na_values='?', header=None)
        imp = SimpleImputer(missing_values=pd.NA, strategy='mean', verbose=0)
        imp.fit(df)
        df = imp.transform(df)
        feature = np.concatenate((feature,df))

    for file in label_paths:
        df = pd.read_table(file,header=None)
        label = np.concatenate((label,df))
    label = np.ravel(label)
    return feature, label

if __name__ == '__main__':
    featurePaths = ['A/A.feature','B/B.feature','C/C.feature','D/D.feature','E/E.feature']
    labelPaths = ['A/A.label','B/B.label','C/C.label','D/D.label','E/E.label']
    x_train, y_train = load_dataset(featurePaths[:4], labelPaths[:4])
    x_test, y_test = load_dataset(featurePaths[4:], labelPaths[4:])

    print("Start training knn")
    knn = KNeighborsClassifier().fit(x_train, y_train)
    print("Training done")
    answer_knn = knn.predict(x_test)
    print("Prediction done")

    print("Start training DT")
    dt = DecisionTreeClassifier().fit(x_train, y_train)
    print("Training done")
    answer_dt = dt.predict(x_test)
    print("Prediction done")

    print("Start training Bayes")
    gnb = GaussianNB().fit(x_train, y_train)
    print("Training done")
    answer_gnb = gnb.predict(x_test)
    print("Prediction done")

    print("\n\nThe classification report for knn:")
    print(classification_report(y_test, answer_knn))

    print("\n\nThe classification report for dt:")
    print(classification_report(y_test, answer_dt))

    print("\n\nThe classification report for gnb:")
    print(classification_report(y_test, answer_gnb))

 数据链接:

链接:https://pan.baidu.com/s/1zFwrucWuJvk4X9hakQzufw?pwd=o0aj 
提取码:o0aj

 

 代码运行结果如下

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值