Giter Site home page Giter Site logo

machinelearning_hw_cqut's Introduction

Machine Learning Homework

环境

python==3.7

numpy>=1.15.1

scikit-learn>=1.0

matplotlib>=2.2.3

pandas>=0.23.4

scipy>=1.1.0

安装

安装有两种方法:

  1. pip 安装

python3.7安装(win10):https://blog.csdn.net/weixin_43790276/article/details/89439352

如果已经有python环境,在终端上运行

pip install -r requirements.txt
  1. conda 安装

** !!!!!建议最好用anaconda配置python环境,简单又方便**

windows:https://blog.csdn.net/weixin_43715458/article/details/100096496

macOS:https://blog.csdn.net/lq_547762983/article/details/81003528

linux:https://blog.csdn.net/cckavin/article/details/86663352

安装了conda环境之后,打开终端,运行

conda create -n ML python=3.7
source activate ML (or conda activate ML)
conda install scikit-learn
conda install matplotlib

撰写和阅读md文件推荐下载Mark Text:GitHub - marktext/marktext: 📝A simple and elegant markdown editor, available for Linux, macOS and Windows.

More

关于作业的一切问题,可以直接发邮件咨询[email protected]

或者在issue上留言提问,如果我有时间看的话就会处理大家的问题。

machinelearning_hw_cqut's People

Contributors

mousecpn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

machinelearning_hw_cqut's Issues

老师,为什么加入正则化防止过拟合之后准确率降低了?

原使用的网络如下:
def init(self):
super(Net,self).init()
self.conv1 = nn.Conv2d(1, 16, kernel_size=5)
self.conv2 = nn.Conv2d(16, 32, kernel_size=5)
self.mp = nn.MaxPool2d(2)
self.relu = nn.ReLU()
self.fc1 = nn.Linear(120,84)
self.fc2 = nn.Linear(84,10)
self.logsoftmax = nn.LogSoftmax()

def forward(self,x):
    in_size = x.size(0)
    out = self.relu(self.mp(self.conv1(x)))
    out = self.relu(self.conv2(out))
    out = out.view(in_size, -1)
    out = self.relu(self.fc1(out))
    out = self.fc2(out)
    return self.logsoftmax(out)

准确率为:0.9756,查看损失函数发现如图所示中间出现过拟合现象,因此在优化器中加入weight_decay=1e-5指定权值衰减率。从图像上看,过拟合现象有好转,但是精确度却略有下降0.9728。请问这是正常情况吗
图片1
图片2

老师,请问使用正规方程计算时矩阵不可逆怎么办呢?

代码如下:

#! python3
# -*- encoding: utf-8 -*-
"""
Created on Mon Sep  26 08:02:10 2022

@author: eanson
"""
import pandas as pd
import torch
import math

import os

# 训练集比例
train_proportion = 0.7

#####################################################################
data_file = os.path.join('HW1 linear model', 'data1.txt')
data = pd.read_csv(data_file, header=None, names=[
                   "Room Size", "Room Amount", "Price"])
# 训练集按照比例划分
m = math.floor(len(data)*train_proportion)
X_train_pd, y_train_pd, X_cv_pd, y_cv_pd = data.iloc[:m, 0:2], data.iloc[:m,
                                                                         2], data.iloc[m+1:, 0:2], data.iloc[m+1:, 2]
# 转换为张量格式
X_train, y_train = torch.tensor(
    X_train_pd.values), torch.tensor(y_train_pd.values)
X_cv, y_cv = torch.tensor(X_cv_pd.values), torch.tensor(y_cv_pd.values)

############################################################################
# 正规方程
"""
$$
w=(X^TX)^{-1}X^Ty
$$
"""
w = X_train.t().mm(X_train).inverse().mm(X_train.t()).mm(y_train)

报错:

(d2l) yanshengdeMacBook-Pro:MachineLearning_HW_CQUT eanson$  cd /Users/eanson/Documents/ml/MachineLearning_HW_CQUT ; /usr/bin/env /Users/eanson/opt/miniconda3/envs/d2l/bin/python /Users/eanson/.vscode/extensions/ms-python.python-2021.2.633441544/pythonFiles/lib/python/debugpy/launcher 59765 -- /Users/eanson/Documents/ml/MachineLearning_HW_CQUT/linear_regression.py 
Traceback (most recent call last):
  File "/Users/eanson/Documents/ml/MachineLearning_HW_CQUT/linear_regression.py", line 37, in <module>
    w = X_train.t().mm(X_train).inverse().mm(X_train.t()).mm(y_train)
RuntimeError: "linalg_inv_out_cpu" not implemented for 'Long'

具体就是调用Inverse函数时,前面的矩阵不可逆😄

mnist benchmark

for sharing the test set performance in mnist and the training experience

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.