序章では、MovieLens 1M データセットの処理例が紹介されています。この本では、データ セットが GroupLens Research () から提供されていることが紹介されています。このアドレスからは、MovieLens の Web サイトからさまざまな評価データ セットが提供されているところに直接ジャンプできます。必要な MovieLens 1M データ セットは、対応する圧縮パッケージをダウンロードできます。そこにもあります。
ダウンロードして解凍したフォルダーは次のとおりです:
この例では、これら 3 つのデータ テーブルが使用されます。私が読んだ「Python For Data Analysis」の中国語版 (PDF) は 2014 年の初版です。その中のすべての例は Python 2.7 と pandas 0.8.2 に基づいて書かれており、私は Python 3.5.2 と pandas 0.8 をインストールしました。 2. pandas 0.20.2 では、一部の関数とメソッドがまったく異なりますが、その一部は新しいバージョンで変更されたパラメーターですが、一部は新しいバージョンでは非推奨になっています。これにより、本の When サンプル コードに従って実行することができました。 、いくつかのエラーと警告が発生します。 MovieLens 1M データ セット コードを私と同じ構成環境でテストすると、次の問題が発生します。
-
dat データを pandas DataFrame オブジェクトに読み取るとき、本に記載されているコードは次のとおりです:
users = pd.read_table('ml-1m/users.dat', sep='::', header=None, names=unames) rnames = ['user_id', 'movie_id', 'rating', 'timestamp'] ratings = pd.read_table('ml-1m/ratings.dat', sep='::', header=None, names=rnames) mnames = ['movie_id', 'title', 'genres'] movies = pd.read_table('ml-1m/movies.dat', sep='::', header=None, names=mnames)
直接実行する場合、警告:
F:/python/HelloWorld/DataAnalysisByPython-1.py:4: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators (separators > 1 char and different from '\s+' are interpreted as regex); you can avoid this warning by specifying engine='python'. users = pd.read_table('ml-1m/users.dat', sep='::', header=None, names=unames) F:/python/HelloWorld/DataAnalysisByPython-1.py:7: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators (separators > 1 char and different from '\s+' are interpreted as regex); you can avoid this warning by specifying engine='python'. ratings = pd.read_table('ml-1m/ratings.dat', sep='::', header=None, names=rnames) F:/python/HelloWorld/DataAnalysisByPython-1.py:10: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators (separators > 1 char and different from '\s+' are interpreted as regex); you can avoid this warning by specifying engine='python'. movies = pd.read_table('ml-1m/movies.dat', sep='::', header=None, names=mnames)
ただし、それも可能ですしかし、完璧な強迫性障害である私は、それでもこの警告を解決したいと思っています。この警告は、「C」エンジンがサポートしていないため、「Python」エンジンにのみフォールバックでき、pandas.read_table メソッドにエンジン パラメータが存在し、これはどの解析エンジンを設定するために使用されることを意味します。 「C」と「Python」を含む、これら 2 つのオプションを使用します。 「C」エンジンはこれをサポートしていないため、エンジンを「Python」に設定するだけで済みます。
users = pd.read_table('ml-1m/users.dat', sep='::', header=None, names=unames, engine = 'python') rnames = ['user_id', 'movie_id', 'rating', 'timestamp'] ratings = pd.read_table('ml-1m/ratings.dat', sep='::', header=None, names=rnames, engine = 'python') mnames = ['movie_id', 'title', 'genres'] movies = pd.read_table('ml-1m/movies.dat', sep='::', header=None, names=mnames, engine = 'python')
-
pivot_table メソッドを使用して、集計されたデータの性別ごとの各映画の平均スコアを計算します。本に記載されているコードは次のとおりです。 、エラーが報告されます: このコードは実行できません:
mean_ratings = data.pivot_table('rating', rows='title', cols='gender', aggfunc='mean')
TypeError は、ここの 'rows' パラメータがメソッドで使用可能なキーワード パラメータではないことを示しています。公式 Web サイトにアクセスして pandas API の使用法ドキュメント () を確認したところ、
pandas.pivot_table のキーワード パラメーターがバージョン 0.20.2 で変更されたことが原因であることがわかりました。同じ効果を達成するには、行をインデックスに置き換えるだけです。同時に、cols パラメーターはなく、代わりに列を使用する必要があります。Traceback (most recent call last): File "F:/python/HelloWorld/DataAnalysisByPython-1.py", line 19, in <module>mean_ratings = data.pivot_table('rating', rows='title', cols='gender', aggfunc='mean') TypeError: pivot_table() got an unexpected keyword argument 'rows'</module>
女性視聴者の好きな映画を理解するために、DataFrame メソッドを使用して列 F を降順に並べ替えます。本のサンプル コードは次のとおりです。警告はプログラムに干渉しません:
mean_ratings = data.pivot_table('rating', index='title', columns='gender', aggfunc='mean')
これは、並べ替えのためのsort_indexメソッドが将来言語またはライブラリで変更される可能性があり、代わりにsort_valuesを使用することが推奨されることを意味します。 API 使用法のドキュメントでは、pandas.DataFrame.sort_index の説明は「ラベルごとにオブジェクトを (軸に沿って) 並べ替える」となっており、一方、pandas.DataFrame.sort_values の説明は「いずれかの軸に沿った値によって並べ替える」となっています。どちらも同じ効果を得るには、sort_values に置き換えます。 sort_index は次の「スコア差の計算
」でも使用されますが、sort_values で置き換えることもできます。top_female_ratings = mean_ratings.sort_index(by='F', ascending=False)
最後のエラーはまだ並べ替えに関連しています。 「評価乖離の計算」でスコアデータの標準偏差を計算した後、フィルターされた値に基づいて系列が降順に並べ替えられます。本のコードは次のとおりです:
F:/python/HelloWorld/DataAnalysisByPython-1.py:32: FutureWarning: by argument to sort_index is deprecated, pls use .sort_values(by=...) top_female_ratings = mean_ratings.sort_index(by='F', ascending=False)
这里的错误是:
Traceback (most recent call last): File "F:/python/HelloWorld/DataAnalysisByPython-1.py", line 47, in <module>print(rating_std_by_title.order(ascending=False)[:10]) File "E:\Program Files\Python35\lib\site-packages\pandas\core\generic.py", line 2970, in __getattr__return object.__getattribute__(self, name) AttributeError: 'Series' object has no attribute 'order'</module>
居然已经没有这个order的方法了,只好去API文档中找替代的方法用。有两个,sort_index和sort_values,这和DataFrame中的方法一样,为了保险起见,我选择使用sort_values:
print(rating_std_by_title.sort_values(ascending=False)[:10]
得到的结果和数据展示的结果一样,可以放心使用。
第三方库不同版本间的差异还是挺明显的,建议是使用最新的版本,在使用时配合官网网站上的API使用文档,轻松解决各类问题~
以上がデータ分析のための Python ラーニング パスの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

Arraysinpython、特にvianumpy、arecrucialinscientificComputing fortheirefficienty andversitility.1)彼らは、fornumericaloperations、data analysis、andmachinelearning.2)numpy'simplementation incensuresfasteroperationsthanpasteroperations.3)arayableminablecickick

Pyenv、Venv、およびAnacondaを使用して、さまざまなPythonバージョンを管理できます。 1)Pyenvを使用して、複数のPythonバージョンを管理します。Pyenvをインストールし、グローバルバージョンとローカルバージョンを設定します。 2)VENVを使用して仮想環境を作成して、プロジェクトの依存関係を分離します。 3)Anacondaを使用して、データサイエンスプロジェクトでPythonバージョンを管理します。 4)システムレベルのタスク用にシステムPythonを保持します。これらのツールと戦略を通じて、Pythonのさまざまなバージョンを効果的に管理して、プロジェクトのスムーズな実行を確保できます。

numpyarrayshaveveraladvantages-averstandardpythonarrays:1)thealmuchfasterduetocベースのインプレンテーション、2)アレモレメモリ効率、特にlargedatasets、および3)それらは、拡散化された、構造化された形成術科療法、

パフォーマンスに対する配列の均一性の影響は二重です。1)均一性により、コンパイラはメモリアクセスを最適化し、パフォーマンスを改善できます。 2)しかし、タイプの多様性を制限し、それが非効率につながる可能性があります。要するに、適切なデータ構造を選択することが重要です。

craftexecutablepythonscripts、次のようになります

numpyarraysarasarebetterfornumeroperations andmulti-dimensionaldata、whilethearraymoduleissuitable forbasic、1)numpyexcelsinperformance and forlargedatasentassandcomplexoperations.2)thearraymuremememory-effictientivearientfa

NumPyArraySareBetterforHeavyNumericalComputing、whilethearrayarayismoreSuitableformemory-constrainedprojectswithsimpledatatypes.1)numpyarraysofferarays andatiledance andpeperancedatasandatassandcomplexoperations.2)thearraymoduleisuleiseightweightandmemememe-ef

ctypesallowsinging andmanipulatingc-stylearraysinpython.1)usectypestointerfacewithclibrariesforperformance.2)createc-stylearraysfornumericalcomputations.3)passarraystocfunctions foreffientientoperations.how、how、becuutiousmorymanagemation、performanceo


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

mPDF
mPDF は、UTF-8 でエンコードされた HTML から PDF ファイルを生成できる PHP ライブラリです。オリジナルの作者である Ian Back は、Web サイトから「オンザフライ」で PDF ファイルを出力し、さまざまな言語を処理するために mPDF を作成しました。 HTML2FPDF などのオリジナルのスクリプトよりも遅く、Unicode フォントを使用すると生成されるファイルが大きくなりますが、CSS スタイルなどをサポートし、多くの機能強化が施されています。 RTL (アラビア語とヘブライ語) や CJK (中国語、日本語、韓国語) を含むほぼすべての言語をサポートします。ネストされたブロックレベル要素 (P、DIV など) をサポートします。

SAP NetWeaver Server Adapter for Eclipse
Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン

EditPlus 中国語クラック版
サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

ホットトピック









