最近學習python在網上找到乙個很好的小入門級的專案但是發現由於版本的問題,不能直接執行,於是自己修改了一下
**實現:
import sys
from pandas.plotting import scatter_matrix
print('python: {}'.format(sys.version))
# scipy
import scipy
print('scipy: {}'.format(scipy.__version__))
# numpy
import numpy
print('numpy: {}'.format(numpy.__version__))
# matplotlib
import matplotlib
import matplotlib.pyplot as plt
print('matplotlib: {}'.format(matplotlib.__version__))
# pandas
import pandas
print('pandas: {}'.format(pandas.__version__))
# scikit-learn
import sklearn
from sklearn.model_selection import kfold
from sklearn.linear_model import logisticregression
from sklearn.discriminant_analysis import lineardiscriminantanalysis
print('sklearn: {}'.format(sklearn.__version__))
# load dataset
url = ""
names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'class']
dataset = pandas.read_csv(url, names=names)
# shape
print(dataset.shape)
# descriptions
print(dataset.describe())
# box and whisker plots
dataset.plot(kind='box', subplots=true, layout=(2, 2), sharex=false, sharey=false)
plt.show()
# histograms
dataset.hist()
plt.show()
# scatter plot matrix
scatter_matrix(dataset)
plt.show()
# split-out validation dataset
array = dataset.values
x = array[:, 0:4]
y = array[:, 4]
validation_size = 0.20
seed = 7
x_train, x_validation, y_train, y_validation = sklearn.model_selection.train_test_split(x, y, test_size=validation_size, random_state=seed)
# test options and evaluation metric
seed = 7
scoring = 'accuracy'
#spot check algorithms
models =
# evaluate each model in turn
results =
names =
for name, model in models:
kfold = kfold(n_splits=10, random_state=seed)
cv_results = sklearn.model_selection.cross_val_score(model, x_train, y_train, cv=kfold, scoring=scoring)
msg = "%s: %f (%f)" % (name, cv_results.mean(), cv_results.std())
print(msg)
# compare algorithms
fig = plt.figure()
fig.suptitle('algorithm comparison')
ax = fig.add_subplot(111)
plt.boxplot(results)
ax.set_xticklabels(names)
plt.show()
# make predictions on validation dataset
knn = sklearn.neighbors.kneighborsclassifier()
knn.fit(x_train, y_train)
predictions = knn.predict(x_validation)
print(sklearn.metrics.accuracy_score(y_validation, predictions))
print(sklearn.metrics.confusion_matrix(y_validation, predictions))
print(sklearn.metrics.classification_report(y_validation, predictions))
Python入門經典 程式設計專案(三)
1.dna 排序 dna排序指確定dna分子中的腺嘌呤 胸腺嘧啶 胞嘧啶和鳥嘌呤鹼基的順序 標準表示法的基礎使用其首字母 atcg 所以dna是用4個字元構成的字串。dna字串可能會有百萬個單位 字元 長。子串匹配 substring matching 是乙個過程,確定乙個較短的字串 子串 是否包含...
Python入門之Django專案的建立
首先,安裝好python之後,要使用django先需要建立乙個虛擬環境,進入到你想存放django專案的碟符下,執行cmd切換到當前目錄然後使用命令python m venv blog blog是檔名 建立好虛擬環境如圖 在使用命令 blog script activate來啟用虛擬環境 啟用虛擬環...
Python資料分析入門實戰專案
首先匯入要使用的科學計算包numpy,pandas,視覺化matplotlib,seaborn,以及機器學習包sklearn。import pandas as pd import numpy as np import seaborn as sns import matplotlib as mpl i...