「Pythonでグラフデータベース Neo4j入門 for ビギナー」とか銘打っておきながら私自身もビギナーなので、すみません。 PythonでNeo4jを操作する環境構築と、データをいじってみるサンプルをご紹介します。 1. Neo4jの導入 まず、Mac OSXにNeo4Jを導入する方法から始めます。私の環境がYosemite 10.10.2なのでもし環境違いで何かエラー等あればコメント等で教えていただけると嬉しいです。 まず、JDKが必要ですが、Macに最初から入っているJavaではうまく動かないそうなので Oracle JDK 7を http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html から導入します。 次に、 http://neo4j.com/download/ にア
class Levenshtein: #ここで配列を立ち上げて、初期値を入れる def initArray(self,str1,str2): distance = [] for i in range(len(str1)+1): distance.append([0]*(len(str2)+1)) distance[i][0] = i for j in range(len(str2)+1): distance[0][j] = j return distance #セルに値を入れる def editDist(self,str1,str2,distance): dist = [0]*3 for i in range(1,len(str1)+1): for j in range(1,len(str2)+1): dist[0] = distance[i-1][j-1] if str1[i-1]==s
Pandas でデータを扱うことで、データ分析の前処理が格段に楽になります。 列データにおける NaN の処理を例に、Pandasの便利さの説明をしたいと思います。 NaNとはNaN(Not a Number) は浮動小数点型における異常な値のことを意味します。 わかりやすい例で言うと、0での割り算が該当します。これは実数では表せないため、 NaN になります。 Pandas において NaN は 値が欠損している 場合によく遭遇する表現です。 具体例で見ていきましょう。以下のようなサンプルデータ(sample.csv)を作成します。 ID,名前,年齢,性別,趣味 1,小林,20,男,野球観戦 2,田中,35,女,飲み会 3,佐藤,29,男 4,鈴木,44,女,編み物データを read_csv 関数で読み出して DataFrame とした後、表示してみます。 1import pandas
2020年新年最初の投稿です 色々とPython製のライブラリについて調べていたら、仕事でも使えそうなライブラリを見つけたので、今回はそれを試してみます。 地名から座標を割り出す今回はジオコーディングの一種でもある地名や住所から座標を割り出してくれるPython Geocoderというのを使っていきます。Geocoderというものは、多言語にもあるライブラリだそうです。 Geocoderの特徴は、複数のマップサービスのAPIを統一されたスキーマや文法などで代わりに呼び出してくれます。 約30個近くのマップサービスに対応しており、GeocoderからGoogleMap、OpenStreetMapとあらゆるマップサービスからマップの情報を引き出してくれます。 ちなみにGoogleMapなどはAPI Keyが必要ですが、API Keyを設定していなくても、API Key不要なOpenStreet
前のエントリーでは、PHPでGeoIPを使ってIPアドレスを解析した。 本エントリーでは、Pythonを使ったやり方をメモ。と、言ってもほぼPHPと同じw データベースのダウンロード 上記のエントリーと同様なので、上記のエントリーを参照のこと。 インストール インストールにはpipを使う。pipのインストールに関しては、pythonを使っている場合大抵インストールされていると思われるので省略する。 PHPと同様にGithubの公式ページが参考になる。 GeoIP2 Python APIのインストール $ pip install geoip2 これでインストールは完了。 使ってみる 以下のサイトを参考に、PythonでもIPアドレスから地域の情報を取得してみる。 サンプルコード import geoip2.database # データベースの読み込み reader = geoip2.data
ヒストグラムを作成するhist関数 基数の数を変更する (bins) ラベルを元にヒストグラムを作成する by 非数値データの頻度をヒストグラムで表示する まとめ 参考 Pandasにもヒストグラムを作成する関数hist()が存在します。この関数は値を表示するのではなく、ヒストグラムをmatplotlibを使ってプロットします。単純に頻度の数値データが欲しい場合はvalues_counts関数が便利な関数です。 本記事では ヒストグラムの作成の仕方 value_counts関数を使った非数値データの頻度の出力方法 について解説します。 今回扱うサンプルデータはKaggleのチュートリアルからとってきたものです。 Titanic - Kaggle ここのtrain.csvという名前のファイルを使います。 (ダウンロードするためにはユーザー登録が必要ですが簡単なものなのでしておくことをお勧めし
主成分分析(principal component analysis)とは多変量解析手法のうち次元削減手法としてよく用いられる手法の一種で、相関のある多変数から、相関のない少数で全体のばらつきを最もよく表す変数を合成します。 主成分分析を行う便利なツールとして、Pythonで利用可能なScikit-learnなどがありますが、ここではScikit-learnでのPCAの使い方を概観したあと、Scikit-learnを使わずにpandasとnumpyだけでPCAをしてみることで、Pythonの勉強とPCAの勉強を同時に行いたいと思います。 プログラミングにおいて大事なのは「コピペ・タブ補完・ヒストリー機能を極力使うこと」、「一字一句を理解できないと先に進めないのではなく、まずは全部を理解できなくてもいいからゴールまで辿り着き、中身の理解はその後ですること」、「出来上がっているコードの中で、ど
pivot_table関数 APIドキュメント params: returns: ピボットテーブルを作成する 複数要素を元に多層化させる データの個数をカウントする 列ごとと行ごとの合計を表示 複数の統計量を表示させる 関数を使って統計処理を指定する 欠損値を補完 欠損値があるデータも表示させる まとめ 参考 ピボットテーブルとはエクセルで有名な機能の1つで馴染みの方も多いかもしれません。 複雑なデータ構造を一目で分かりやすくする目的でよく使われるもので、クロス集計したものをまとめたものとなります。 2つの要素間の相関が分かりやすく現れるので使いこなせると重宝するでしょう。例えば男女間での科目ごとの平均点といったものをひと目で把握することができます。 Pandasでも手軽にピボットテーブルを作成できるpivot_table関数が実装されています。 そこで本記事ではpivot_table関数
pandas.DataFrameの複数の列の文字列を結合(連結)して新たな列を生成する方法について、以下の内容を説明する。 文字列の列同士の結合(連結) str.cat() +演算子 欠損値NaNの処理 文字列の列と数値の列の結合(連結) 連結した列をpandas.DataFrameに追加 例として、以下のデータを使用する。 import pandas as pd df = pd.read_csv('data/src/sample_pandas_normal.csv').head(3) print(df) # name age state point # 0 Alice 24 NY 64 # 1 Bob 42 CA 92 # 2 Charlie 18 CA 70
2016年に作った資料を公開します。もう既にいろいろ古くなってる可能性が高いです。 (追記:新しい記事は 階層的クラスタリングとシルエット係数 をご覧ください。) 本実習では教師なし学習の一種である階層的クラスタリングを行ないます。 * 階層的クラスタリング とは何か、知らない人は下記リンク参照↓ * 階層的クラスタリングとは * クラスタリング (クラスター分析) まずはサンプルデータの取得から # URL によるリソースへのアクセスを提供するライブラリをインポートする。 import urllib # ウェブ上のリソースを指定する url = 'https://raw.githubusercontent.com/maskot1977/ipython_notebook/master/toydata/iris.txt' # 指定したURLからリソースをダウンロードし、名前をつける。 url
前回の記事の続きです。 参考:scipyで階層的クラスタリング 前回の記事で階層的クラスタリングを実行し可視化するところまで紹介しましたが、 今回は一歩戻ってlinkage関数の戻り値の中身を見てみます。 とりあえず、 linkage matrix をprintして結果を見てみましょう。 from sklearn.datasets import load_iris from scipy.cluster.hierarchy import linkage X = load_iris().data[::10, 2:4] print(X.shape) # (15, 2) # ユークリッド距離とウォード法を使用してクラスタリング z = linkage(X, metric='euclidean', method='ward') print(z.shape) # (14, 4) print(z) #
GuidesGet startedInstallationModels & LanguagesFacts & FiguresspaCy 101New in v3.7New in v3.6New in v3.5GuidesLinguistic FeaturesPOS TaggingMorphologyLemmatizationDependency ParseNamed EntitiesEntity LinkingTokenizationMerging & SplittingSentence SegmentationMappings & ExceptionsVectors & SimilarityLanguage DataRule-based MatchingProcessing PipelinesEmbeddings & TransformersLarge Language Modelsne
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く