Skip to content

Latest commit

 

History

History
67 lines (53 loc) · 1.43 KB

R_vs_Python.md

File metadata and controls

67 lines (53 loc) · 1.43 KB

Comparison of R and Python for Data Analysis

Syntax

R Syntax

# Load the iris dataset
iris <- read.csv("iris.csv")
str(iris)

Python Syntax

# Load the iris dataset
import pandas as pd
iris = pd.read_csv("iris.csv")
print(iris.info())

Libraries

R Libraries

library(C50)
iris_model <- C5.0(iris_train[-5], iris_train$variety)

Python Libraries

from sklearn.tree import DecisionTreeClassifier
iris_model = DecisionTreeClassifier()
iris_model.fit(iris_train.iloc[:, :-1], iris_train.iloc[:, -1])

Performance

R Performance

summary(iris_model)

Python Performance

from sklearn.metrics import classification_report
print(classification_report(iris_test['variety'], iris_predict))

Use Cases

R Use Cases

library(arules)
plants <- read.transactions("plants.csv", sep = ",")
summary(plants)

Python Use Cases

from mlxtend.frequent_patterns import apriori
plants = pd.read_csv("plants.csv")
frequent_itemsets = apriori(plants, min_support=0.0731, use_colnames=True)
print(frequent_itemsets)

Conclusion

Both R and Python are powerful tools for data analysis. R is particularly strong in statistical analysis and visualization, while Python excels in machine learning and general-purpose programming. The choice between R and Python depends on the specific needs of the project and the familiarity of the user with the language.