// UCI 165: retain one 28-day outcome per distinct seven-ingredient formulation. // Output two consecutive CSV tables: 417 lines of features, then 84 of outcomes. import aner.data let ingredients = List("Cement", "Blast Furnace Slag", "Fly Ash", "Water", "Superplasticizer", "Coarse Aggregate", "Fine Aggregate") var schema = data.schema() for col in Range(ingredients.len()) { schema = schema.column(cast(ingredients.get(col)), "Float64", false) } schema = schema.column("Age", "Int64", false) .column("Concrete compressive strength", "Float64", false) let raw = data.scan_csv("data/concrete-uci.csv", schema, "NA").collect() let first_id = Dictionary() let strengths = Dictionary() let counts = Dictionary() for row in Range(raw.rows()) { if raw.integer(row, "Age") == 28 { let amounts = List() for col in Range(ingredients.len()) { let name = cast(ingredients.get(col)) amounts.append(String(raw.number(row, name))) } let key = ",".join(amounts) if !first_id.contains(key) { first_id.set(key, row + 1) } let strength = raw.number(row, "Concrete compressive strength") strengths.set(key, cast(strengths.get_or(key, 0.0)) + strength) counts.set(key, cast(counts.get_or(key, 0)) + 1) } } let recipes = first_id.keys() let outcomes = List() print("row_id,split,cement,slag,fly_ash,water,superplasticizer,coarse,fine,strength_mpa") for index in Range(recipes.len()) { let key = cast(recipes.get(index)) let id = String(cast(first_id.get(key))) let measured = cast(strengths.get(key)) / Float64(cast(counts.get(key))) if (index + 1) % 5 == 0 { print(id + ",candidate," + key + ",NA") outcomes.append(id + "," + String(measured)) } else { print(id + ",train," + key + "," + String(measured)) } } print("row_id,strength_mpa") for index in Range(outcomes.len()) { print(cast(outcomes.get(index))) }