python pyforest库怎么使用

发布时间:2021-12-17 17:30:57 作者:iii
来源:亿速云 阅读:159

本篇内容主要讲解“python pyforest库怎么使用”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“python pyforest库怎么使用”吧!

还记得入门Python数据分析时经常会import几个库,下面这几个可谓是入门学习时的四大护法,Python数据处理和可视化常会用的工具。  
 
python pyforest库怎么使用  

不知道大家有没有遇到过这样一个问题,每次重新开启一个建模流程或者分析过程时,会重新敲一遍import或者将之前的import代码copy进去。虽然已经用的滚花烂熟了,但是确耗费不必要的时间。


一个示例

python pyforest库怎么使用

看到了吧,开头什么都没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库怎么使用”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

推荐阅读:
  1. 关于python中pyforest的案例分析
  2. Python库pyforest有什么优点

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

python pyforest

上一篇:怎么在CKB上实现用户自定义Token

下一篇:如何进行springboot配置templates直接访问的实现

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》