本篇内容主要讲解“python pyforest库怎么使用”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“python pyforest库怎么使用”吧!
不知道大家有没有遇到过这样一个问题,每次重新开启一个建模流程或者分析过程时,会重新敲一遍import或者将之前的import代码copy进去。虽然已经用的滚花烂熟了,但是确耗费不必要的时间。
一个示例
看到了吧,开头什么都没import,依然可以正常使用常用库。
安装
需要安装Python3.6以上的版本,然后终端运行:
pip install pyforest
使用方法
非常简单!!!
一行代码就可以解决。
from pyforest import *
如果使用Jupyter或IPython,甚至可以跳过此行,因为pyforest会将其自身添加到自动启动中。
而且,完成脚本后,可以通过以下方式导出所有导入语句:
active_imports()
通过这个指令,我们就可以看到脚本所涉及到的全部已经被我省略的库。
好了,你可能会问,如果需要的库不在pyforest中怎么办?
首先,pyforest支持大部分流行的数据科学库,比如pandas,numpy,matplotlib,seaborn,sklearn,tensorflow等等,以及常用的辅助库如os,sys,re,pickle等。
### Data Wranglingpd = LazyImport("import pandas as pd")
np = LazyImport("import numpy as np")
dd = LazyImport("from dask import dataframe as dd")SparkContext = LazyImport("from pyspark import SparkContext")
load_workbook = LazyImport("from openpyxl import load_workbook")
### Data Visualization and Plottingmpl = LazyImport("import matplotlib as mpl")plt = LazyImport("import matplotlib.pyplot as plt")
sns = LazyImport("import seaborn as sns")
py = LazyImport("import plotly as py")go = LazyImport("import plotly.graph_objs as go")px = LazyImport("import plotly.express as px")
dash = LazyImport("import dash")
bokeh = LazyImport("import bokeh")
alt = LazyImport("import altair as alt")
pydot = LazyImport("import pydot")
# statisticsstatistics = LazyImport("import statistics")
### Machine Learningsklearn = LazyImport("import sklearn")OneHotEncoder = LazyImport("from sklearn.preprocessing import OneHotEncoder")TSNE = LazyImport("from sklearn.manifold import TSNE")train_test_split = LazyImport("from sklearn.model_selection import train_test_split")svm = LazyImport("from sklearn import svm")GradientBoostingClassifier = LazyImport( "from sklearn.ensemble import GradientBoostingClassifier")GradientBoostingRegressor = LazyImport( "from sklearn.ensemble import GradientBoostingRegressor")RandomForestClassifier = LazyImport( "from sklearn.ensemble import RandomForestClassifier")RandomForestRegressor = LazyImport("from sklearn.ensemble import RandomForestRegressor")
TfidfVectorizer = LazyImport( "from sklearn.feature_extraction.text import TfidfVectorizer")
# TODO: add all the other most important sklearn objects# TODO: add separate sections within machine learning viz. Classification, Regression, Error Functions, Clustering
# Deep Learningtf = LazyImport("import tensorflow as tf")keras = LazyImport("import keras")
# NLPnltk = LazyImport("import nltk")gensim = LazyImport("import gensim")spacy = LazyImport("import spacy")re = LazyImport("import re")
### Helpersys = LazyImport("import sys")os = LazyImport("import os")re = LazyImport("import re")glob = LazyImport("import glob")Path = LazyImport("from pathlib import Path")
pickle = LazyImport("import pickle")
dt = LazyImport("import datetime as dt")
tqdm = LazyImport("import tqdm")
其次,如果真的没有也没关系,pyforest支持向其中添加库。操作方法也很简单,找到pyforest库的user_imports.py文件,然后添加一个语句就好了,比如像下面这样:
################################ User-specific imports ################################# You can save your own imports in ~/.pyforest/user_imports.py# Please note: imports in ~/.pyforest/user_imports.py take precedence over the# imports above.
到此,相信大家对“python pyforest库怎么使用”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/219826.html