images\cherry_red.png1 Python
      images\cherry_blue.png1.1 爬虫
         images\cherry_orange.png1.1.1 多线程
         images\cherry_orange.png1.1.2 B站
         images\cherry_orange.png1.1.3 zmq71多线程爬取
         images\cherry_orange.png1.1.4 jable.tv多线程爬取
            images\cherry_cyan.png1.1.4.1 jable.tv细节
         images\cherry_orange.png1.1.5 python执行js代码
         images\cherry_orange.png1.1.6 windows代理配置
      images\cherry_blue.png1.2 Linux编译升级3.9版本
      images\cherry_blue.png1.3 数据分析
         images\cherry_orange.png1.3.1 预测考研成绩
   images\cherry_red.png2 Python django
      images\cherry_blue.png2.1 目录层面说明
         images\cherry_orange.png2.1.1 urls.py
         images\cherry_orange.png2.1.2 settings.py
         images\cherry_orange.png2.1.3 M 模型数据库
         images\cherry_orange.png2.1.4 T templates/...html
         images\cherry_orange.png2.1.5 V(逻辑处理) views.py
      images\cherry_blue.png2.2 django模板
         images\cherry_orange.png2.2.1 模板标签
            images\cherry_cyan.png2.2.1.1 过滤器
            images\cherry_cyan.png2.2.1.2 标签
               images\cherry_orange_dark.png2.2.1.2.1 if/else
               images\cherry_orange_dark.png2.2.1.2.2 for
               images\cherry_orange_dark.png2.2.1.2.3 ifequal/ifnotequal
               images\cherry_orange_dark.png2.2.1.2.4 csrf_token
            images\cherry_cyan.png2.2.1.3 模板继承
         images\cherry_orange.png2.2.2 自定义标签和过滤器
      images\cherry_blue.png2.3 django模型ORM
         images\cherry_orange.png2.3.1 App应用
            images\cherry_cyan.png2.3.1.1 models.py
         images\cherry_orange.png2.3.2 SQL
            images\cherry_cyan.png2.3.2.1 新增
            images\cherry_cyan.png2.3.2.2 删除
            images\cherry_cyan.png2.3.2.3 更新
            images\cherry_cyan.png2.3.2.4 查询
         images\cherry_orange.png2.3.3 单表示例
         images\cherry_orange.png2.3.4 多表示例
         images\cherry_orange.png2.3.5 聚合查询
         images\cherry_orange.png2.3.6 分组查询
      images\cherry_blue.png2.4 django表单
         images\cherry_orange.png2.4.1 GET
         images\cherry_orange.png2.4.2 POST
         images\cherry_orange.png2.4.3 Request
      images\cherry_blue.png2.5 django视图
      images\cherry_blue.png2.6 django路由
      images\cherry_blue.png2.7 django Admin管理
      images\cherry_blue.png2.8 django组件
         images\cherry_orange.png2.8.1 Form页面组件
         images\cherry_orange.png2.8.2 Auth用户认证
         images\cherry_orange.png2.8.3 Cookie/Session
         images\cherry_orange.png2.8.4 中间件
         images\cherry_orange.png2.8.5 视图FBV/CBV
      images\cherry_blue.png2.9 django+nginx+uwsgi
      images\cherry_blue.png2.10 Python小知识
         images\cherry_orange.png2.10.1 def __int__(self):
         images\cherry_orange.png2.10.2 def __str__(self):
         images\cherry_orange.png2.10.3 @staticmethod
         images\cherry_orange.png2.10.4 @wraps
         images\cherry_orange.png2.10.5 pycharm
需求: 使用二分类算法实现,提供往年同学课程期末成绩和考研成绩,通过课程期末成绩预测,这一届学生考研是否能考取成功,0代表没有成功,1代表考上


import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
import random
import csv
# 读取数据
data = pd.read_csv('data.csv')
"""
划分训练集和测试集
    test_size 表示测试集占总数据集的比例
    random_state 随机数种子,可自行定义,保证训练模型唯一
"""
X_train, X_test, y_train, y_test = train_test_split(data.iloc[:, :-2], data.iloc[:, -1], test_size=0.2,
                                                    random_state=random.randint(0, 1024))

# 定义模型
# 参考文档 https://scikit-learn.org/stable/modules/preprocessing.html
model = LogisticRegression()

# 训练模型
model.fit(X_train, y_train)
# 在测试集上测试模型准确率
y_pred = model.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)
print('模型准确率:', accuracy)

test_d = []
# 测试数据验证
with open('test.csv', newline='', encoding='utf-8') as csvfile:
    # 创建csv reader对象
    reader = csv.reader(csvfile)
    # 遍历每一行数据,并转换为列表
    for row in reader:
        test_d.append(row)

for d in range(1, len(test_d)):
    title_d = test_d[0][:-2]
    new_d = pd.DataFrame([test_d[d][:-2]],columns=title_d)
    y_new = model.predict(new_d)
    print(new_d)
    # 0 or 1  0表示未过线,1表示已过线
    print('是否过线: ', y_new)