• 大小: 7.27MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-09-23
  • 语言: Python
  • 标签: python  CNN  SVM  

资源简介

经典模型对应的python代码经典模型对应的python代码

资源截图

代码片段和文件信息

import numpy as np
import matplotlib.pyplot as plt


# Read dataset
x y = [] []
for sample in open(“../_Data/prices.txt“ “r“):
    xx yy = sample.split(““)
    x.append(float(xx))
    y.append(float(yy))
x y = np.array(x) np.array(y)
# Perform normalization
x = (x - x.mean()) / x.std()
# Scatter dataset
plt.figure()
plt.scatter(x y c=“g“ s=20)
plt.show()

x0 = np.linspace(-2 4 100)


# Get regression model under LSE criterion with degree ‘deg‘
def get_model(deg):
    return lambda input_x=x0: np.polyval(np.polyfit(x y deg) input_x)


# Get the cost of regression model above under given x y
def get_cost(deg input_x input_y):
    return 0.5 * ((get_model(deg)(input_x) - input_y) ** 2).sum()

# Set degrees
test_set = (1 4 10)
for d in test_set:
    print(get_cost(d x y))

# Visualize results
plt.scatter(x y c=“g“ s=20)
for d in test_set:
    plt.plot(x0 get_model(d)() label=“degree = {}“.format(d))
plt.xlim(-2 4)
plt.ylim(1e5 8e5)
plt.legend()
plt.show()

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\
     文件        1184  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\.gitignore
     目录           0  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Data\
     文件         120  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Data\balloon1.0(en).txt
     文件         438  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Data\balloon1.0.txt
     文件         438  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Data\balloon1.5.txt
     文件         424  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Data\balloon2.0.txt
     文件     5604839  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Data\bank1.0.txt
     文件     8559529  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Data\cifar10.txt
     文件     5205193  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Data\madelon.txt
     文件     8103179  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Data\mnist.txt
     文件      373704  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Data\mushroom.txt
     文件         563  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Data\prices.txt
     文件         379  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Data\test.txt
     目录           0  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Dist\
     目录           0  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Dist\ImageRecognition\
     目录           0  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Dist\ImageRecognition\_Data\
     目录           0  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Dist\ImageRecognition\_Data\_Cache\
     文件          80  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Dist\ImageRecognition\_Data\_Cache\LABEL_DIC.npy
     文件           0  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Dist\ImageRecognition\_Data\Put Training Dataset FOLDERS here
     文件        6108  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Dist\ImageRecognition\Main.py
     目录           0  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Dist\ImageRecognition\Models\
     目录           0  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Dist\ImageRecognition\Models\Extractors\
     目录           0  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Dist\ImageRecognition\Models\Extractors\v3\
     文件           0  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Dist\ImageRecognition\Models\Extractors\v3\Put v3 Extractor here as ‘Model.pb‘
     文件        2946  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Dist\ImageRecognition\README.md
     目录           0  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Dist\ImageRecognition\Test\
     文件           0  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Dist\ImageRecognition\Test\Put testing pictures here
     文件       19644  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Dist\ImageRecognition\ToolBox.py
     目录           0  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Dist\NeuralNetworks\
     目录           0  2018-06-21 15:25  MachineLearning-master\MachineLearning-master\_Dist\NeuralNetworks\_Tests\
............此处省略278个文件信息

评论

共有 条评论