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:
IMPORTANT BE SURE TO SAY NO
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: /usr/bin/python3
## libpython: /usr/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.so
## pythonhome: //usr://usr
## version: 3.8.10 (default, Jun 2 2021, 10:49:15) [GCC 9.4.0]
## numpy: /usr/lib/python3/dist-packages/numpy
## numpy_version: 1.17.4
#SAY NO SAY NO SAY NO
data(rock) to load it.head() function to print out the first six rows of the dataset.##r chunk
data(rock)
head(rock,n=6 )
## 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##
##convert to pandas
import pandas as pd
from sklearn import datasets
dataset_boston= datasets.load_boston()
df_boston = pd.DataFrame(data=dataset_boston.data, columns=dataset_boston.feature_names)
df_boston.head()
## CRIM ZN INDUS CHAS NOX ... RAD TAX PTRATIO B LSTAT
## 0 0.00632 18.0 2.31 0.0 0.538 ... 1.0 296.0 15.3 396.90 4.98
## 1 0.02731 0.0 7.07 0.0 0.469 ... 2.0 242.0 17.8 396.90 9.14
## 2 0.02729 0.0 7.07 0.0 0.469 ... 2.0 242.0 17.8 392.83 4.03
## 3 0.03237 0.0 2.18 0.0 0.458 ... 3.0 222.0 18.7 394.63 2.94
## 4 0.06905 0.0 2.18 0.0 0.458 ... 3.0 222.0 18.7 396.90 5.33
##
## [5 rows x 13 columns]
QUESTION: Look in your environment window. What do you see? ANSWER: CRIM ZN INDUS CHAS NOX … RAD TAX PTRATIO B LSTAT 0 0.00632 18.0 2.31 0.0 0.538 … 1.0 296.0 15.3 396.90 4.98 1 0.02731 0.0 7.07 0.0 0.469 … 2.0 242.0 17.8 396.90 9.14 2 0.02729 0.0 7.07 0.0 0.469 … 2.0 242.0 17.8 392.83 4.03 3 0.03237 0.0 2.18 0.0 0.458 … 3.0 222.0 18.7 394.63 2.94 4 0.06905 0.0 2.18 0.0 0.458 … 3.0 222.0 18.7 396.90 5.33
py$VARNAME.DATAFRAME$COLUMN. Try to print out the CRIM column from your df_boston variable.##r chunk
##r chunk
#py$VARNAME
#df_boston$CRIM
$, we use . like this: r.VARNAME.DATAFRAME["COLUMNNAME"]. Try printing out the shape column in the rock dataset.##python chunk
r.rock
## area peri shape perm
## 0 4990 2791.900 0.090330 6.3
## 1 7002 3892.600 0.148622 6.3
## 2 7558 3930.660 0.183312 6.3
## 3 7352 3869.320 0.117063 6.3
## 4 7943 3948.540 0.122417 17.1
## 5 7979 4010.150 0.167045 17.1
## 6 9333 4345.750 0.189651 17.1
## 7 8209 4344.750 0.164127 17.1
## 8 8393 3682.040 0.203654 119.0
## 9 6425 3098.650 0.162394 119.0
## 10 9364 4480.050 0.150944 119.0
## 11 8624 3986.240 0.148141 119.0
## 12 10651 4036.540 0.228595 82.4
## 13 8868 3518.040 0.231623 82.4
## 14 9417 3999.370 0.172567 82.4
## 15 8874 3629.070 0.153481 82.4
## 16 10962 4608.660 0.204314 58.6
## 17 10743 4787.620 0.262727 58.6
## 18 11878 4864.220 0.200071 58.6
## 19 9867 4479.410 0.144810 58.6
## 20 7838 3428.740 0.113852 142.0
## 21 11876 4353.140 0.291029 142.0
## 22 12212 4697.650 0.240077 142.0
## 23 8233 3518.440 0.161865 142.0
## 24 6360 1977.390 0.280887 740.0
## 25 4193 1379.350 0.179455 740.0
## 26 7416 1916.240 0.191802 740.0
## 27 5246 1585.420 0.133083 740.0
## 28 6509 1851.210 0.225214 890.0
## 29 4895 1239.660 0.341273 890.0
## 30 6775 1728.140 0.311646 890.0
## 31 7894 1461.060 0.276016 890.0
## 32 5980 1426.760 0.197653 950.0
## 33 5318 990.388 0.326635 950.0
## 34 7392 1350.760 0.154192 950.0
## 35 7894 1461.060 0.276016 950.0
## 36 3469 1376.700 0.176969 100.0
## 37 1468 476.322 0.438712 100.0
## 38 3524 1189.460 0.163586 100.0
## 39 5267 1644.960 0.253832 100.0
## 40 5048 941.543 0.328641 1300.0
## 41 1016 308.642 0.230081 1300.0
## 42 5605 1145.690 0.464125 1300.0
## 43 8793 2280.490 0.420477 1300.0
## 44 3475 1174.110 0.200744 580.0
## 45 1651 597.808 0.262651 580.0
## 46 5514 1455.880 0.182453 580.0
## 47 9718 1485.580 0.200447 580.0