From 1af270742bcb4ddd27bda2c8f1095428fa8d4258 Mon Sep 17 00:00:00 2001 From: Carlos Kelly Date: Thu, 28 Sep 2023 11:41:30 -0500 Subject: [PATCH] Add Python support. --- .changeset/many-eyes-travel.md | 5 ++++ packages/demo/src/sample-code.ts | 27 ++++++++++++++++++++++ packages/generate-prism-languages/index.ts | 1 + 3 files changed, 33 insertions(+) create mode 100644 .changeset/many-eyes-travel.md diff --git a/.changeset/many-eyes-travel.md b/.changeset/many-eyes-travel.md new file mode 100644 index 0000000..111e7d4 --- /dev/null +++ b/.changeset/many-eyes-travel.md @@ -0,0 +1,5 @@ +--- +"prism-react-renderer": minor +--- + +Add Python support. diff --git a/packages/demo/src/sample-code.ts b/packages/demo/src/sample-code.ts index b35f8cc..8328eea 100644 --- a/packages/demo/src/sample-code.ts +++ b/packages/demo/src/sample-code.ts @@ -108,6 +108,33 @@ end if `, }, + ["Python"]: { + language: "python", + code: ` +from sklearn.datasets import load_iris +from sklearn.model_selection import train_test_split +from sklearn.tree import DecisionTreeClassifier +from sklearn.metrics import accuracy_score, classification_report + +iris = load_iris() +X = iris.data +y = iris.target + +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42) + +clf = DecisionTreeClassifier(random_state=42) +clf.fit(X_train, y_train) + +y_pred = clf.predict(X_test) + +accuracy = accuracy_score(y_test, y_pred) +report = classification_report(y_test, y_pred) +print(f"Accuracy: {accuracy}") +print("Classification Report:\\n", report) +print("Feature Importances:", clf.feature_importances_) + `, + }, + ["Rust"]: { language: "rust", code: ` diff --git a/packages/generate-prism-languages/index.ts b/packages/generate-prism-languages/index.ts index 9f3de8d..d6b1e86 100644 --- a/packages/generate-prism-languages/index.ts +++ b/packages/generate-prism-languages/index.ts @@ -21,6 +21,7 @@ export const languagesToBundle = [ "cpp", "markdown", "html", + "python", ] /**