• Skip to main content
  • Skip to primary sidebar

学習記録

プログラミング

素数

2018年1月28日 by 河副 太智 Leave a Comment

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import csv
import numpy as np
 
#素数は2以上なので0から開始lastは任意の数
own_nm = 0
last = 11
 
#任意の数の整数値を出す
a = np.array(np.arange(2,last))
 
#設定した整数値の数だけ回す
for i in range((len(a))-1):
    #自身の数を削除
    own_delated = np.delete(a,own_nm)
    
    
    
    
#     for x in range((len(own_delated))):
#         if own_delated[x] %
 
 
 
 
#次の数値の素数判定    
    own_nm += 1
    
    
print(own_delated)

 

Filed Under: 作成実績

タイタニック

2018年1月28日 by 河副 太智 Leave a Comment

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
%matplotlib inline
 
 
#データの読込み
df = pd.read_csv('train.csv')
 
#欠損値処理1 Fareは平均値、乗船地は一般的なSを代入
df['Fare'] = df['Fare'].fillna(df['Fare'].median())
df['Embarked'] = df['Embarked'].fillna('S')
 
#欠損地処理2
#年齢をfillnaで平均を取るとランダムフォレストの結果が
#訓練スコア  0.96
#テストスコア 0.80
#年齢は学習において重要なのでNaの場合行ごと削除した結果
#訓練スコア  0.98
#テストスコア 0.81に上昇した
df=df.dropna(subset=['Age'])
 
#カテゴリ変数の変換
df['Sex'] = df['Sex'].apply(lambda x: 1 if x == 'male' else 0)
df['Embarked'] = df['Embarked'].map( {'S': 0, 'C': 1, 'Q': 2} ).astype(int)
 
 
#学習に不要と思われるデータを削除
df = df.drop(['Cabin','Name','PassengerId','Ticket'],axis=1)
 
 
#訓練データとテストデータに分離
train_X = df.drop('Survived', axis=1)
train_y = df.Survived
(train_X, test_X ,train_y, test_y) = train_test_split(train_X, train_y, test_size = 0.3, random_state = 666)
 
 
 
#複数のモデル構築でどの分類器がベストかを調べる
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC
from sklearn.linear_model import LinearRegression
from sklearn.linear_model import Ridge
 
 
#決定木
ki = DecisionTreeClassifier(random_state=0).fit(train_X, train_y)
 
#ランダムフォレスト
mori = RandomForestClassifier(random_state=0).fit(train_X,train_y)
 
#ロジスティック回帰
logi = LogisticRegression(C=0.1).fit(train_X,train_y)
 
#KNN
KNN = KNeighborsClassifier(4).fit(train_X,train_y)
 
#SVC
svc = SVC(probability=True).fit(train_X,train_y)
 
#linear
linear = LinearRegression().fit(train_X,train_y)
 
#ridge
ridge = Ridge(alpha=1).fit(train_X,train_y)
 
 
data ={"clf": ["tree", "forest","logistic","KNN","svc","Linear","Ridge"],
      "traning score":[(ki.score(train_X,train_y)),(mori.score(train_X,train_y)),
                      (logi.score(train_X,train_y)),(KNN.score(train_X,train_y)),
                      (svc.score(train_X,train_y)),(linear.score(train_X,train_y)),
                       (ridge.score(train_X,train_y))],      
      "test score":[(ki.score(test_X,test_y)),(mori.score(test_X,test_y)),
                   logi.score(train_X,train_y),(KNN.score(test_X,test_y)),
                   (svc.score(test_X,test_y)),(linear.score(train_X,train_y)),(ridge.score(train_X,train_y))]
      }
 
frame = pd.DataFrame(data,index=["tree", "forest","logistic","KNN","svc","Linear","Ridge"])
 
 
frame.plot(kind="bar")

 

Filed Under: 作成実績

機械学習の特徴量抽出を英語で

2018年1月27日 by 河副 太智 Leave a Comment

Feature Extraction

Filed Under: Python 基本

複数のグラフを表示

2018年1月25日 by 河副 太智 Leave a Comment

複数のグラフを表示

ax=ax1
と
ax=ax2で分ける

1
2
3
4
5
6
df = pd.read_csv('train.csv')
fig = plt.figure()
ax1 = fig.add_subplot(1,2,1)
ax2 = fig.add_subplot(1,2,2)
sns.barplot(x="Age",y="Sex",hue='Survived',data=df, ax=ax1)
sns.countplot('Sex',hue='Survived',data=df, ax=ax2)

 

Filed Under: グラフ

matplotlibでグラフをpngに変換

2018年1月24日 by 河副 太智 Leave a Comment

matplotlibでグラフをpngに変換

1
2
3
4
5
6
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
 
plt.plot([1,2,3,4,5,4,3,2,1])
plt.savefig("aaa.png")

 

Filed Under: グラフ

‘int’ object is not iterableが出た場合

2018年1月23日 by 河副 太智 Leave a Comment

‘int’ object is not iterableが出た場合forでin len()を設定すると
オブジェクトの数値が対象となってしまうのでin range()を使用する

1
for i in range((len(a))):

 

Filed Under: python3

  • « Go to Previous Page
  • Page 1
  • Interim pages omitted …
  • Page 14
  • Page 15
  • Page 16
  • Page 17
  • Page 18
  • Interim pages omitted …
  • Page 55
  • Go to Next Page »

Primary Sidebar

カテゴリー

  • AWS
  • Bootstrap
  • Dash
  • Django
  • flask
  • GIT(sourcetree)
  • Plotly/Dash
  • VPS
  • その他tool
  • ブログ
  • プログラミング
    • Bokeh
    • css
    • HoloViews
    • Jupyter
    • Numpy
    • Pandas
    • PosgreSQL
    • Python 基本
    • python3
      • webアプリ
    • python3解説
    • scikit-learn
    • scipy
    • vps
    • Wordpress
    • グラフ
    • コマンド
    • スクレイピング
    • チートシート
    • データクレンジング
    • ブロックチェーン
    • 作成実績
    • 時系列分析
    • 機械学習
      • 分析手法
      • 教師有り
    • 異常値検知
    • 自然言語処理
  • 一太郎
  • 数学
    • sympy
      • 対数関数(log)
      • 累乗根(n乗根)
    • 暗号学

Copyright © 2025 · Genesis Sample on Genesis Framework · WordPress · Log in