资源简介
吴恩达机器学习课后作业python代码
代码片段和文件信息
import numpy as np
from scipy import stats
from sklearn.metrics import f1_score classification_report
# X data shape
# array([[ 13.04681517 14.74115241]
# [ 13.40852019 13.7632696 ]
# [ 14.19591481 15.85318113]
# [ 14.91470077 16.17425987]
# [ 13.57669961 14.04284944]])
def select_threshold(X Xval yval):
“““use CV data to find the best epsilon
Returns:
e: best epsilon with the highest f-score
f-score: such best f-score
“““
# create multivariate model using training data
mu = X.mean(axis=0)
cov = np.cov(X.T)
multi_normal = stats.multivariate_normal(mu cov)
# this is key use CV data for fine tuning hyper parameters
pval = multi_normal.pdf(Xval)
# set up epsilon candidates
epsilon = np.linspace(np.min(pval) np.max(pval) num=10000)
# calculate f-score
fs = []
for e in epsilon:
y_pred = (pval <= e).astype(‘int‘)
fs.append(f1_score(yval y_pred))
# find the best f-score
argmax_fs = np.argmax(fs)
return epsilon[argmax_fs] fs[argmax_fs]
def predict(X Xval e Xtest ytest):
“““with optimal epsilon combine X Xval and predict Xtest
Returns:
multi_normal: multivariate normal model
y_pred: prediction of test data
“““
Xdata = np.concatenate((X Xval) axis=0)
mu = Xdata.mean(axis=0)
cov = np.cov(Xdata.T)
multi_normal = stats.multivariate_normal(mu cov)
# calculate probability of test data
pval = multi_normal.pdf(Xtest)
y_pred = (pval <= e).astype(‘int‘)
print(classification_report(ytest y_pred))
return multi_normal y_pred
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-10-19 21:59 ex1-linear regression\
目录 0 2017-10-19 21:59 ex1-linear regression\.ipynb_checkpoints\
文件 242296 2017-09-30 19:39 ex1-linear regression\.ipynb_checkpoints\1.linear_regreesion-checkpoint.ipynb
文件 267341 2017-09-30 19:39 ex1-linear regression\.ipynb_checkpoints\1.linear_regreesion_v1-checkpoint.ipynb
文件 54033 2017-09-30 19:39 ex1-linear regression\.ipynb_checkpoints\2- batch gradient decent-checkpoint.ipynb
文件 189637 2017-09-30 19:39 ex1-linear regression\.ipynb_checkpoints\3- optional section-checkpoint.ipynb
文件 88765 2017-09-30 19:39 ex1-linear regression\.ipynb_checkpoints\4- tensoflow batch gradient decent-checkpoint.ipynb
文件 140749 2017-10-19 00:06 ex1-linear regression\.ipynb_checkpoints\ML-Exercise1-checkpoint.ipynb
文件 265724 2017-10-18 21:01 ex1-linear regression\1.linear_regreesion_v1.ipynb
文件 140749 2017-10-19 00:06 ex1-linear regression\ML-Exercise1.ipynb
文件 489928 2017-09-27 22:01 ex1-linear regression\ex1.pdf
文件 1456 2017-09-27 22:01 ex1-linear regression\ex1data1.txt
文件 704 2017-09-27 22:01 ex1-linear regression\ex1data2.txt
目录 0 2017-10-19 21:59 ex2-logistic regression\
目录 0 2017-10-19 21:59 ex2-logistic regression\.ipynb_checkpoints\
文件 46036 2017-09-30 19:39 ex2-logistic regression\.ipynb_checkpoints\1- visualize data-checkpoint.ipynb
文件 302807 2017-09-30 19:39 ex2-logistic regression\.ipynb_checkpoints\1. logistic_regression_v1-checkpoint.ipynb
文件 108205 2017-09-30 19:39 ex2-logistic regression\.ipynb_checkpoints\2- logistic regression-checkpoint.ipynb
文件 295061 2017-09-30 19:39 ex2-logistic regression\.ipynb_checkpoints\2. logistic_regression-checkpoint.ipynb
文件 78000 2017-09-30 19:39 ex2-logistic regression\.ipynb_checkpoints\3- regularized logistic regression-checkpoint.ipynb
文件 180797 2017-09-30 19:39 ex2-logistic regression\.ipynb_checkpoints\4- experiment with lambda constant for regularization-checkpoint.ipynb
文件 101947 2017-10-18 21:54 ex2-logistic regression\.ipynb_checkpoints\ML-Exercise2-v1-checkpoint.ipynb
文件 78 2017-10-19 00:08 ex2-logistic regression\.ipynb_checkpoints\Unti
文件 301119 2017-10-18 21:23 ex2-logistic regression\1. logistic_regression_v1.ipynb
文件 101947 2017-10-18 21:54 ex2-logistic regression\ML-Exercise2-v1.ipynb
文件 2738 2017-10-19 00:08 ex2-logistic regression\Unti
文件 233661 2017-09-27 22:01 ex2-logistic regression\ex2.pdf
文件 3875 2017-09-27 22:01 ex2-logistic regression\ex2data1.txt
文件 2351 2017-09-27 22:01 ex2-logistic regression\ex2data2.txt
目录 0 2017-10-19 23:24 ex3-neural network\
目录 0 2017-10-19 21:59 ex3-neural network\.ipynb_checkpoints\
............此处省略124个文件信息
相关资源
- 机器学习字母分类-python
- 吴恩达机器学习编程作业python3版本
- Python机器学习算法-mobi文字版-附带m
- Pandas 0.19.2 官方文档 汉化中文版(精
- [书签+文字版]Python Machine Learning 2nd
- matlab和python的神经网络
- 《机器学习实战》pdf及所和数据集文
- Python-用于物体跟踪的全卷积连体网络
- Python-数学建模竞赛中所使用的相关算
- Python-MonoDepthPyTorchPyTorch无监督单目深
- Python-用Tensorflowjs实现的可回收非可回
- NumPy攻略:Python科学计算与数据分析
- Python Machine Learning 2nd Edition [Sebastian
- 机器学习——推荐系统python实现
- Python-利用TensorFlow中的深度学习进行图
- Introduction to Machine Learning with Python_正
- Python机器学习经典 中文完整版高清
- deep learning with python中文版232513
- Python机器学习经典 源代码
- Python-TensorFlow快速入门与实战课件与参
- Python-FCN完全卷积网络中最简单最容易
- Python-匈牙利算法卡尔曼滤波器多目标
- Python-mathAI一个拍照做题程序输入一张
- 机器学习分类算法分析及基于Python的
- Python-20182019校招春招秋招算法NLP深度
- python机器学习及实践
- Python机器学习实践指南.pdf+代码+数据
- Python机器学习Sebastian著-带书签
- 吴恩达机器学习python代码
- Python机器学习经典及随书代码
评论
共有 条评论