Database Reference
In-Depth Information
2.
We can use that function to call reduce on the instances and remove the attributes
as we go:
(defn delete-attrs [instances attr-names]
(reduce (fn [is n]
(.deleteAttributeAt is (attr-n is n)) is)
instances
attr-names))
3.
Finally, we can use the following to delete the attributes I mentioned earlier:
(delete-attrs data [:agri-percent])
Hiding columns
There are a few attributes that we'll hide. Instead of destructively deleting attributes from one
set of instances, iltering them creates a new dataset without the hidden attributes. It can be
useful to have one dataset for clustering and another with the complete information for the
dataset (for example, a name or ID attribute). For this example, I'll take out the country code:
1.
Weka does this by applying a filter class to a dataset to create a new dataset.
We'll use the Remove ilter in this function. This also uses the attr-n function, which
was used earlier in this recipe:
(defn filter-attributes [dataset remove-attrs]
(let [attrs (map inc
(map (partial attr-n dataset)
remove-attrs))
options (->options
"-R"
(str/join \, (map str attrs)))
rm (doto (Remove.)
(.setOptions options)
(.setInputFormat dataset))]
(Filter/useFilter dataset rm)))
2. We can call this function with the attribute names that we want to ilter out:
(def data-numbers
(filter-attributes data [:country-code]))
And we can see the results.
user=> (map #(.. data-numbers (attribute %) name)
(range (.numAttributes data-numbers)))
("year" "total-land" "agri-total")
 
Search WWH ::




Custom Search