This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %load_ext autoreload | |
| %autoreload 2 | |
| import sys | |
| sys.path.append("../") | |
| import components.data | |
| import components.features | |
| import components.training |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fit(train_X, train_y): | |
| rf_model = RandomForestRegressor(random_state=1, n_estimators=10) | |
| rf_model.fit(train_X, train_y) | |
| return rf_model | |
| def validate(model, val_X, val_y): | |
| rf_val_predictions = model.predict(val_X) | |
| return mean_absolute_error(rf_val_predictions, val_y) | |
| rf_model = fit(train_X, train_y) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rf_model = RandomForestRegressor(random_state=1, n_estimators=10) | |
| rf_model.fit(train_X, train_y) | |
| rf_val_predictions = rf_model.predict(val_X) | |
| rf_val_mae = mean_absolute_error(rf_val_predictions, val_y) | |
| print("Validation MAE for Random Forest Model: {:,.0f}".format(rf_val_mae)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * We can't write 'new T()' in Java, and it wouldn't be typesafe if we could. Some people blame type erasure for this, but | |
| * the real problem is that we haven't specified that T has a zero-argument constructor, we just assumed it. | |
| * To do it properly, encode the constructors through generics. No runtime type information needed... | |
| */ | |
| interface Constructor0<T> { | |
| T make(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| boolean r = isOrdered(Arrays.asList(1, 3, 5, 7)); // true | |
| boolean r2 = isOrdered(Arrays.asList(1, 5, 5, 7)); // false | |
| boolean r3 = isOrdered(Arrays.asList(5, 3, 6, 7)); // false | |
| public static <T extends Comparable<T>> boolean isOrdered(Collection<T> collection) { | |
| final Iterator<T> i = collection.iterator(); | |
| final Iterator<T> j = collection.iterator(); | |
| j.next(); | |
| while(j.hasNext()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def loopA = { | |
| // 0 1 2 3 | |
| var i = 0 | |
| while(i < 4) { | |
| print(i) | |
| i = i + 1 | |
| } | |
| println("") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface Semigroup<T> { | |
| T apply(T a, T b); | |
| } | |
| interface Monoid<T> extends Semigroup<T> { | |
| T identity(); | |
| } | |
| interface Group<T> extends Monoid<T> { | |
| T inverse(T a); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ReifiableType<T> { | |
| final T value; | |
| final Class<T> type; | |
| public ReifiableType(T value, Class<T> type) { | |
| this.value = value; | |
| this.type = type; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Iterator; | |
| class GeneratorTest { | |
| public static void main(String[] args) { | |
| /** | |
| * A generator for Fibonacci numbers | |
| */ | |
| Generator<Integer> g = new Generator<>(new Sequencer<Integer>() { | |
| private int a = 1, b = 1; | |
| public Integer get() { |