Update README.md
Browse files
README.md
CHANGED
|
@@ -19,4 +19,40 @@ Finally, it predicts the word for any given number (like 45) and decodes it back
|
|
| 19 |
|
| 20 |
Example:
|
| 21 |
|
| 22 |
-
45 → Model predicts label → Decoder converts to "forty-five"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
Example:
|
| 21 |
|
| 22 |
+
45 → Model predicts label → Decoder converts to "forty-five"
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
Usage:
|
| 30 |
+
|
| 31 |
+
from sklearn.tree import DecisionTreeClassifier
|
| 32 |
+
from sklearn.preprocessing import LabelEncoder
|
| 33 |
+
|
| 34 |
+
# Create input numbers from 1 to 100
|
| 35 |
+
X = [[i] for i in range(1, 1000)]
|
| 36 |
+
|
| 37 |
+
# Create corresponding output words
|
| 38 |
+
def number_to_word(n):
|
| 39 |
+
import inflect
|
| 40 |
+
p = inflect.engine()
|
| 41 |
+
return p.number_to_words(n)
|
| 42 |
+
|
| 43 |
+
y = [number_to_word(i) for i in range(1, 1000)]
|
| 44 |
+
|
| 45 |
+
# Encode the output words to numbers
|
| 46 |
+
le = LabelEncoder()
|
| 47 |
+
y_encoded = le.fit_transform(y)
|
| 48 |
+
|
| 49 |
+
# Train the ML model
|
| 50 |
+
model = DecisionTreeClassifier()
|
| 51 |
+
model.fit(X, y_encoded)
|
| 52 |
+
|
| 53 |
+
# Predict: Try with any number from 1 to 100
|
| 54 |
+
input_number = [[345]] # Change this value as needed
|
| 55 |
+
predicted_encoded = model.predict(input_number)
|
| 56 |
+
predicted_word = le.inverse_transform(predicted_encoded)
|
| 57 |
+
|
| 58 |
+
print(f"Input: {input_number[0][0]} → Output: {predicted_word[0]}")
|