Skip to content

Commit 9c041df

Browse files
Merge pull request #226 from FormidableLabs/feature/python
Add Python support.
2 parents 87ce248 + 1af2707 commit 9c041df

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

.changeset/many-eyes-travel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"prism-react-renderer": minor
3+
---
4+
5+
Add Python support.

packages/demo/src/sample-code.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,33 @@ end if
108108
`,
109109
},
110110

111+
["Python"]: {
112+
language: "python",
113+
code: `
114+
from sklearn.datasets import load_iris
115+
from sklearn.model_selection import train_test_split
116+
from sklearn.tree import DecisionTreeClassifier
117+
from sklearn.metrics import accuracy_score, classification_report
118+
119+
iris = load_iris()
120+
X = iris.data
121+
y = iris.target
122+
123+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
124+
125+
clf = DecisionTreeClassifier(random_state=42)
126+
clf.fit(X_train, y_train)
127+
128+
y_pred = clf.predict(X_test)
129+
130+
accuracy = accuracy_score(y_test, y_pred)
131+
report = classification_report(y_test, y_pred)
132+
print(f"Accuracy: {accuracy}")
133+
print("Classification Report:\\n", report)
134+
print("Feature Importances:", clf.feature_importances_)
135+
`,
136+
},
137+
111138
["Rust"]: {
112139
language: "rust",
113140
code: `

packages/generate-prism-languages/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const languagesToBundle = <const>[
2121
"cpp",
2222
"markdown",
2323
"html",
24+
"python",
2425
]
2526

2627
/**

0 commit comments

Comments
 (0)