For this semester, you have two options:
Only complete the part of the assignment based on your choice for computer or virtual machine!!
##r chunk - do not change these
R.version
## _
## platform x86_64-pc-linux-gnu
## arch x86_64
## os linux-gnu
## system x86_64, linux-gnu
## status
## major 4
## minor 0.5
## year 2021
## month 03
## day 31
## svn rev 80133
## language R
## version.string R version 4.0.5 (2021-03-31)
## nickname Shake and Throw
#RStudio.Version() run this line but it won't knit with it "on"
ANSWER: What version of Rstudio are you using? Please note it should be the latest version! R version 4.0.5 (2021-03-31) ### Install all the R Packages
eval = TRUE to eval = FALSE once you have them installed.install.packages("https://osf.io/ak7gq/download", repos = NULL, method = "libcurl", type = "source")
devtools::install_github("trinker/termco")
devtools::install_github("trinker/coreNLPsetup")
devtools::install_github("trinker/tagger")
devtools::install_github("bnosac/RDRPOSTagger")
devtools::install_github("bradleyboehmke/harrypotter")
reticulate library.##r chunk
library(reticulate)
Try typing py_config() below. You should get a prompt to install Miniconda. If not, use install_miniconda().
##r chunk
py_config()
## python: /home/kshitij_deshpande/.local/share/r-miniconda/envs/r-reticulate/bin/python
## libpython: /home/kshitij_deshpande/.local/share/r-miniconda/envs/r-reticulate/lib/libpython3.6m.so
## pythonhome: /home/kshitij_deshpande/.local/share/r-miniconda/envs/r-reticulate:/home/kshitij_deshpande/.local/share/r-miniconda/envs/r-reticulate
## version: 3.6.12 | packaged by conda-forge | (default, Dec 9 2020, 00:36:02) [GCC 9.3.0]
## numpy: /home/kshitij_deshpande/.local/share/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages/numpy
## numpy_version: 1.19.5
Run py_config() in the R chunk below.
##r chunk
py_config()
## python: /home/kshitij_deshpande/.local/share/r-miniconda/envs/r-reticulate/bin/python
## libpython: /home/kshitij_deshpande/.local/share/r-miniconda/envs/r-reticulate/lib/libpython3.6m.so
## pythonhome: /home/kshitij_deshpande/.local/share/r-miniconda/envs/r-reticulate:/home/kshitij_deshpande/.local/share/r-miniconda/envs/r-reticulate
## version: 3.6.12 | packaged by conda-forge | (default, Dec 9 2020, 00:36:02) [GCC 9.3.0]
## numpy: /home/kshitij_deshpande/.local/share/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages/numpy
## numpy_version: 1.19.5
Windows machines need special programs to make all this work:
py_install("package_name", pip = T)eval = TRUE to eval = FALSE once you have them installed.Packages: nltk, matplotlib, PyQt5, scikit-learn, numpy, pandas, regex, requests, bs4, spacy, contractions, textblob, sip, gensim, afinn, pyLDAvis
library(reticulate)
py_install("nltk",pip = T)
py_install("matplotlib",pip = T)
py_install("PyQt5",pip = T)
py_install("numpy",pip = T)
py_install("pandas",pip = T)
py_install("bs4",pip = T)
py_install("spacy",pip = T)
py_install("contractions",pip = T)
py_install("textblob",pip = T)
py_install("numpy",pip = T)
py_install("gensim",pip = T)
py_install("afinn",pip = T)
py_install("pyLDAvis",pip = T)
py_install("regex",pip = T)
py_install("requests",pip = T)
py_install("sklearn",pip = T)
For nltk, you will need to add a few other pieces. Type the following into R console: - library(reticulate) - repl_python() - Here you should notice you have switched from > to >>> which indicates you are in Python:
To get out of >>> python, type exit or hit the Esc key.
Click on terminal > type in: - python -m spacy download en_core_web_sm - This will download the English language spacy module.
Go to: https://rstudio.thedoomlab.com/auth-sign-in
Your log in is:
Click on terminal and run the following lines:
Run the following in the R console:
When you run py_config() the first time, it will ask you to install miniconda. Say no! We already have python3 installed on the server.
##r chunk
library(reticulate)
py_config()
## python: /home/kshitij_deshpande/.local/share/r-miniconda/envs/r-reticulate/bin/python
## libpython: /home/kshitij_deshpande/.local/share/r-miniconda/envs/r-reticulate/lib/libpython3.6m.so
## pythonhome: /home/kshitij_deshpande/.local/share/r-miniconda/envs/r-reticulate:/home/kshitij_deshpande/.local/share/r-miniconda/envs/r-reticulate
## version: 3.6.12 | packaged by conda-forge | (default, Dec 9 2020, 00:36:02) [GCC 9.3.0]
## numpy: /home/kshitij_deshpande/.local/share/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages/numpy
## numpy_version: 1.19.5
data(rock) to load it.head() function to print out the first six rows of the dataset.##r chunk
data(rock)
head(rock)
## area peri shape perm
## 1 4990 2791.90 0.0903296 6.3
## 2 7002 3892.60 0.1486220 6.3
## 3 7558 3930.66 0.1833120 6.3
## 4 7352 3869.32 0.1170630 6.3
## 5 7943 3948.54 0.1224170 17.1
## 6 7979 4010.15 0.1670450 17.1
sklearn library, it has several sample datasets. You load python packages by using import PACKAGE. Note that you install and call this package different names (scikit-learn = sklearn).from PACKAGE import FUNCTION. Therefore, you should use from sklearn import datasets.boston dataset by doing: dataset_boston = datasets.load_boston()..head() function: df_boston.head(), after converting the file with pandas (code included below).##python chunk
##TYPE HERE##
import sklearn
from sklearn import datasets
##convert to pandas
import pandas as pd
dataset_boston=datasets.load_boston()
df_boston = pd.DataFrame(data=dataset_boston.data, columns=dataset_boston.feature_names)
QUESTION: Look in your environment window. What do you see? #dataset_boston,df_boston
py$VARNAME.DATAFRAME$COLUMN. Try to print out the CRIM column from your df_boston variable.##r chunk
#df_boston$CRIM
$, we use . like this: r.VARNAME.DATAFRAME["COLUMNNAME"]. Try printing out the shape column in the rock dataset.##python chunk
#View(rock['shape'])
#print(rock['shape'])