AI/ML
Feature Importance Card - ML Feature Analysis
Visualize feature importance scores and contribution to model predictions. Analyze which features drive your machine learning model performance.
Feature Importance Card
The Feature Importance Card displays which features have the most impact on model predictions, helping teams understand model behavior and feature engineering priorities.
Preview
Installation
npx shadcn@latest add https://vectormotion.vercel.app/registry/feature-importance-card.jsonFeature Importance Card
'use client'import React from 'react';import { SlidersHorizontal } from 'lucide-react';import { motion } from 'motion/react';import { clsx, type ClassValue } from "clsx"import { twMerge } from "tailwind-merge"import { ResponsiveContainer, BarChart, Bar, XAxis, YAxis, Tooltip, Cell } from 'recharts';function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs))}interface FeatureData { feature: string; importance: number; [key: string]: any;}interface FeatureImportanceCardProps { className?: string; title?: string; subtitle?: string; data?: FeatureData[]; barColor?: string;}const DEFAULT_DATA: FeatureData[] = [ { feature: 'Price', importance: 0.95 }, { feature: 'Age', importance: 0.82 }, { feature: 'Loc', importance: 0.65 }, { feature: 'Size', importance: 0.45 }, { feature: 'Type', importance: 0.30 },];const DEFAULT_TITLE = "Features";const DEFAULT_SUBTITLE = "Global Importance";const DEFAULT_BAR_COLOR = "#3b82f6";export const FeatureImportanceCard: React.FC<FeatureImportanceCardProps> = ({ className = "", title = DEFAULT_TITLE, subtitle = DEFAULT_SUBTITLE, data = DEFAULT_DATA, barColor = DEFAULT_BAR_COLOR,}) => { return ( <motion.div initial={{ opacity: 0, y: 20 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.5, delay: 0.3 }} className={cn( "relative overflow-hidden rounded-2xl border border-border bg-card text-card-foreground shadow-sm transition-all hover:border-blue-300 dark:hover:border-blue-700 hover:shadow-md flex flex-col h-full", className )} > <div className="p-5 flex flex-col h-full relative z-10"> <div className="mb-4 flex items-start justify-between"> <div> <h3 className="font-bold text-lg text-foreground"> {title} </h3> <p className="text-sm text-muted-foreground font-medium"> {subtitle} </p> </div> <div className="rounded-lg border-2 border-blue-100 dark:border-blue-800 p-2 text-blue-500 dark:text-blue-400 flex items-center justify-center"> <SlidersHorizontal className="h-5 w-5" /> </div> </div> <div className="flex-1 w-full min-h-[140px] relative"> <ResponsiveContainer width="100%" height="100%"> <BarChart data={data} layout="vertical" margin={{ top: 5, right: 10, left: 10, bottom: 5 }}> <XAxis type="number" hide /> <YAxis type="category" dataKey="feature" tick={{ fontSize: 10, fill: '#71717a' }} width={30} axisLine={false} tickLine={false} /> <Tooltip cursor={{ fill: 'transparent' }} content={() => null} /> <Bar dataKey="importance" radius={[0, 4, 4, 0]} barSize={12}> {data.map((entry, index) => ( <Cell key={`cell-${index}`} fill={barColor} fillOpacity={0.4 + (entry.importance * 0.6)} /> ))} </Bar> </BarChart> </ResponsiveContainer> </div> <div className="absolute -bottom-4 -right-4 z-0 opacity-5 pointer-events-none"> <SlidersHorizontal className="w-40 h-40 text-blue-500" /> </div> </div> </motion.div> );};Props
Prop
Type
Usage
This component is a demo card displaying feature importance rankings with animated visualizations and dark mode support.